I read a csv file with my code and convert it into an array. This is my code:
$csv_data = array_map('str_getcsv', file('test123.csv'));
$csv_header = $csv_data[0];
unset($csv_data[0]);
foreach($csv_data as $row){
$row = array_combine($csv_header, $row);
echo '<pre>';
print_r($row);
echo '<pre>';
}
And that's the output:
Array
(
[ID] => 1
[article] => 000001
)
Array
(
[ID] => 2
[article] => 000002
)
I'd like the arrays to be in an array, like this:
Array
(
[0] => Array
(
[ID] => 1
[article] => 000001
)
[1] => Array
(
[ID] => 2
[article] => 000002
)
)
Anybody got an idea? It's important that the headers don't get lost.