我有一个数组:
$remove_rownumbers = array(1, 4, 7, 9, 2);
这些是行号,我希望从 PHP 中加载的 CSV 中删除。
现在我想通过这样的计数器和 in_array if 语句遍历行:
$row = 1;
if (($handle = fopen($CSV_FILE, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1500, ",")) !== FALSE) {
if(in_array($row, $remove_rownumbers) == false) // if its not in the remove array, keep it
{
// (...) the output part, where im echoing out each row by foreach($data ...)
}
$row++;
}
}
但是我怎样才能得到现在输出的回声并将其再次正确存储在 CSV 中呢?这样,数组中的行号就不会出现在这个新的行号中
我发现它的开始是这样的:
header('Content-Encoding: UTF-8');
header('Content-type: application/ms-excel; charset=utf-8');
header('Content-Disposition: attachment; filename=output.csv');
echo "\xEF\xBB\xBF";
$fp = fopen("php://output", "w");