I have one csv file "food.csv" and details are in the following order. Total rows are 10 and columns 5. And i wnat the file to be indexed by php to get the array of "Mango".
ITEM,DESC,QTY,RATE,TYPE
124,APPLE,20,300,NEW
123,MANGO,10,500,NEW
135,BANANA,30,600,OLD
148,ORANGE,12,40,NEW
111,MANGO,20,150,OLD
125,APPLE,7,100,OLD
Following is the PHP code but it is not working.
<?php
$eurl = "http://www.xyz.com/food.csv";
if (($handle = fopen ( $eurl, "r" )) !== FALSE) {
$keys = fgetcsv ( $handle, 1000, ";" );
while ( ($data = fgetcsv ( $handle, 1000, ";" )) !== FALSE ) {
if ($r2->id == "MANGO") {
$found = true;
break;
}
$res[] = array_combine($keys, $data);
}
fclose ($handle);
}
var_dump($res);
?>
I require the result in following manner. Can anybody help me in correcting the code?
When the index key is "MANGO", it should give the output as:
MANGO 10 Kgs @ 500USD (123-NEW)
MANGO 20 Kgs @ 150USD (111 -OLD)