Load CSV Into a 2-d Array Using PHP
Loads a CSV file into 2-d array. The first dimention is by line, and the second is comma delimited.
$array = array_map('str_getcsv', file('csvfile.csv'));
array_shift($array);
Example:
csvfile.csv
Company Name,City State,Phone,URL Classic Collections,"Abilene, TX 79602",(325) 672-0000,https://www.facebook.com/Classic-Collections Fabulous Finds,"Abilene, TX 79601",(325) 677-0000,http://www.fabulousfinds.com/ Honeycomb Tree,"Abilene, TX 79601",(325) 338-8000,https://www.facebook.com/The-Honeycomb-Tree/
phpfile.php
$array = array_map('str_getcsv', file('csvfile.csv')); // Loads the csv file as a 2-d array
array_shift($array); // removes the header line
Produces this array:
Array
[0] => Array
[0] => Classic Collections
[1] => Abilene, TX 79602
[2] => (325) 672-0000
[3] => https://www.facebook.com/Classic-Collections )
[1] => Array (
[0] => Fabulous Finds
[1] => Abilene, TX 79601
[2] => (325) 677-0000
[3] => http://www.fabulousfinds.com/ )
[2] => Array (
[0] => Honeycomb Tree
[1] => Abilene, TX 79601
[2] => (325) 338-8000
[3] => https://www.facebook.com/The-Honeycomb-Tree/
)
)