Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP CSV to Associative Array

I have a CSV file that I need to import into an associative array. The data looks like this:

 "General Mills Cereal",http://sidom.com/dyn_li/60.0.75.0/Retailers/Saws/120914_20bp4_img_8934.jpg,$2.25,"9-17.12 oz., select varieties","Valid Sep 14, 2012 - Sep 20, 2012",Saws,"Grocery"

I wan to transform this data into an array where I can grab values like this:

 $items[$row]['title'];
 $items[$row]['imgurl'];
 $items[$row]['itemprice'];
 $items[$row]['itemsize'];
 $items[$row]['expir'];
 $items[$row]['storename'];
 $items[$row]['storetype'];

Where the elements above correspond to my CSV file. How can I import this file into such an array?

like image 849
Ken J Avatar asked Dec 15 '22 19:12

Ken J


1 Answers

I would suggest using the built-in function fgetcsv
There's a simple usage example there also.

like image 175
Noam Avatar answered Dec 22 '22 00:12

Noam