I have a csv files that contains the following lines
enter code here
23,cars,43 063
23,cars,17 306
23,houses,13 300
23,garage,13 094
23,hotels,10 025
22,cars,75 675
22,cars,40 403
22,houses,32 243
22,garage,30 649
22,hotels,29 734
21,hotels,29 734
22,hotels,29 734
And here is the code that i am using to parse the csv file
function readCSV($csvFile){
$file_handle = fopen($csvFile, 'r');
while (!feof($file_handle) ) {
$line_of_text[] = fgetcsv($file_handle, 1024);
}
fclose($file_handle);
return $line_of_text;
}
When i display the contents of the $line_of_text; array, here is what i get
Array
(
[0] => Array
(
[0] => 23
[1] => cars
[2] => 43 063
)
[1] => Array
(
[0] => 23
[1] => cars
[2] => 17 306
)
[2] => Array
(
[0] => 23
[1] => houses
[2] => 13 300
)
.....
But this is not what i want, i would like my array to be displayed in this way
array (
23 => array(
'cars' => 43063,
'houses' => 17306,
'shops' => 13300,
'garages' => 13094,
'hotels' => 10025
),
22 => array(
'cars' => 75675,
'houses' => 40403,
'shops' => 32243,
'garages' => 30649,
'hotels' => 29734,
'test' => 29734
)
);
How do i acheive this ? Can you please help me ?
//UPDATES contents of new my array
Array
(
[0] => Array
(
[0] => cars
[1] => 00
[2] => 0
)
[1] => Array
(
[0] => cars
[1] => 01
[2] => 0
)
[2] => Array
(
[0] => cars
[1] => 02
[2] => 0
)
[3] => Array
(
[0] => cars
[1] => 11
[2] => 0
)
[4] => Array
(
[0] => cars
[1] => 23
[2] => 4425
)
[5] => Array
(
[0] => houses
[1] => 00
[2] => 198
)
[6] => Array
(
[0] => houses
[1] => 01
[2] => 742
)
[7] => Array
(
[0] => houses
[1] => 02
[2] => 168
)
)