第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

根據(jù)條件php創(chuàng)建CSV文件并添加數(shù)據(jù)

根據(jù)條件php創(chuàng)建CSV文件并添加數(shù)據(jù)

PHP
繁華開滿天機(jī) 2022-11-12 13:37:01
我有一組結(jié)果,我想為它創(chuàng)建 csv 文件。但如果結(jié)果有效,我想將電子郵件添加到有效的 csv 文件中,如果它無效,則添加到無效的 csv 文件中。但我無法做到這一點(diǎn)。它將所有電子郵件添加到清理 csv 文件,無效的 csv 為空。有什么建議么結(jié)果是這樣的:Array(    [0] => Array        (            [email] => tamas.szabo@millionverifier.com            [result] => valid        )    [1] => Array        (            [email] => support@millionverifier.com            [result] => valid        ))這是我的條件// creating dirty and clean file$clean_emails = fopen(UPLOAD_DIRECTORY . '/clean/' . $file_name_new . '.' . $extension, 'w');$dirty_emails = fopen(UPLOAD_DIRECTORY . '/dirty/' . $file_name_new . '.' . $extension, 'w');// adding headers to themfputcsv($clean_emails, $headers);fputcsv($dirty_emails, $headers);            if ($results[$i]['result'] === 'valid') {    // adding clean emails to csv    foreach ($results as $row) {    fputcsv($clean_emails, $row);    }    fclose($clean_emails);} elseif ($results[$i]['result'] === 'invalid') {    // adding dirty emails to csv    foreach ($results as $row) {    fputcsv($dirty_emails, $row);    }    fclose($dirty_emails);} else {    // if there are not any dirty or clean emails add them unknown to csv    $unknown_emails = fopen(UPLOAD_DIRECTORY . '/unknown/' . $file_name_new . '.' . $extension, 'w');    fputcsv($unknown_emails, $row);    fclose($unknown_emails);}
查看完整描述

1 回答

?
慕的地8271018

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊

也許你想要逐行分離?


// creating dirty and clean file

$clean_emails = fopen(UPLOAD_DIRECTORY . '/clean/' . $file_name_new . '.' . $extension, 'w');

$dirty_emails = fopen(UPLOAD_DIRECTORY . '/dirty/' . $file_name_new . '.' . $extension, 'w');

$unknown_emails = null; // No file yet


// adding headers to them

fputcsv($clean_emails, $headers);

fputcsv($dirty_emails, $headers);            


foreach ($results as $row) { // Scan each row

    if ($row['result'] === 'valid') {

        fputcsv($clean_emails, $row);

    } elseif ($row['result'] === 'invalid') {

        fputcsv($dirty_emails, $row);

    } else {  // found something else

        if (!isset($unknown_emails)) { // Open file if it was not

            $unknown_emails = fopen(UPLOAD_DIRECTORY . '/unknown/' . $file_name_new . '.' . $extension, 'w');

            fputcsv($unknown_emails, $headers); // Add headers ?

        }

        fputcsv($unknown_emails, $row);

    }

} // end loop

fclose($clean_emails);

fclose($dirty_emails);

if (isset($unknown_emails)) {

    fclose($unknown_emails); // Close 'unknown' if it was opened

}


查看完整回答
反對(duì) 回復(fù) 2022-11-12
  • 1 回答
  • 0 關(guān)注
  • 154 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)