私はcsvファイルから次の配列を読み込んでいます:
Array
(
[0] => Array
(
[0] => book1
[1] => description1
[2] => category1
[3] => code1
[4] => editor1
[5] => 0
[6] => eur
[7] => out of stoc
)
[1] => Array
(
[0] => book2
[1] => description2
[2] => category2
[3] => code2
[4] => editor2
[5] => 0
[6] => curr2
[7] => out of stoc
)
[2] => Array
(
[0] => book3
[1] => description3
[2] => category3
[3] => code3
[4] => editor3
[5] => 0
[6] => curr3
[7] => out of stoc
)
)
コード :
function read_CSV_raza($rzs_csv) {
$file_handle = fopen($rzs_csv, 'r');
while (!feof($file_handle)) {
$line_of_text[] = fgetcsv($file_handle, 1024, ';');
}
fclose($file_handle);
return $line_of_text;
}
$rzs_csv = 'rzs.csv';
$csv = read_CSV_raza($rzs_csv);
このイントロを別の csv ファイルに書き込むために、別の配列 (ヘッダー) を追加したいと考えています。元 :
Array
(
[0] => Array
(
[0] => h1
[1] => h2
[2] => h3
[3] => h4
[4] => h5
[5] => h6
[6] => h7
[7] => h8
)
[1] => Array
(
[0] => book1
[1] => description1
[2] => category1
[3] => code1
[4] => editor1
[5] => 0
[6] => eur
[7] => out of stoc
)
[2] => Array
(
[0] => book2
[1] => description2
[2] => category2
[3] => code2
[4] => editor2
[5] => 0
[6] => curr2
[7] => out of stoc
)
[3] => Array
(
[0] => book3
[1] => description3
[2] => category3
[3] => code3
[4] => editor3
[5] => 0
[6] => curr3
[7] => out of stoc
)
)
array_merge(); で試しました。array_unshift(); しかし、無駄に、必要な結果が得られません。
新しい CSV に配列を書き込むためのタラは次のとおりです。
$fp = fopen('rezultate.csv', 'w') or die("Can't open rezultate.csv");
foreach ($csv as $items) {
fputcsv($fp, $items, ';', '"');
}
fclose($fp) or die("Can't close rezultate.csv");
私はプログラマーではないので、この問題について何か助けていただければ幸いです。