1,2,3,4,5
3,4,1,5,2
5,4,3,2,1
I want to export each row from that file into one multidimensional array as below:
array[0]->[0] = 1
[1] = 2
[2] = 3
[3] = 4
[4] = 5
[1]->[0] = 3
[1] = 4
[2] = 1
[3] = 5
[4] = 2
[2]->[0] = 5
[1] = 4
[2] = 3
[3] = 2
[4] = 1
I have the following code:
Code: Select all
<?php
$row = 0;
$i = 0;
$handle = fopen("num.csv", "r");
while (($data = fgetcsv($handle, 30, ",")) !== FALSE)
{
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c <= $num; $c++)
{
echo $data[$c] . " " . "\n";
$array[$i] .= $data[$c];
$i++;
}
}
echo "<pre>";
echo print_r($array);
echo "</pre>";
fclose($handle);
?>