csvファイルの内容をすべて配列に取り出したいので、fgetcsv
関数を使用しました。正しく動作していますが、配列を返したいときは空です。問題は while ループの外にあるようです。
これが私のコードです:
$filepath="Data\";
$csvfile=array(); /* here i did declaration */
$csvfile=csvcontain($filepath);
print_r($csvfile); /*prints empty array */
function csvcontain($filepath)
{
foreach (glob($filepath."*."."csv") as $filename)
{
$file_handle = fopen($filename, 'r');
while (!feof($file_handle))
{
$csv=fgetcsv($file_handle, 1024);
$csvfile=$csv;
}
}
fclose($file_handle);
return $csvfile;
}
どこが間違っているのかわかりません。