public function csvToArray($filename = '', $delimiter = ','){
if(!file_exists($filename) || !is_readable($filename))
return false;
$header = null;
$data = array();
if(($handle = fopen($filename, 'r')) !== false){
while(($row = fgetcsv($handle, 1000, $delimiter)) !== false){
if(!$header)
$header = $row;
else
$data[] = array_combine($header, $row);
}
fclose($handle);
}
return $data;
}
<?php
/* Map Rows and Loop Through Them */
$rows = array_map('str_getcsv', file('file.csv'));
$header = array_shift($rows);
$csv = array();
foreach($rows as $row) {
$csv[] = array_combine($header, $row);
}
?>
$array = $fields = array();
$handle = @fopen("yourcsvfilename.csv", "r");
if($handle){
while(($row = fgetcsv($handle, 4096)) !== False){
if(empty($fields)){
$fields = $row;
continue;
}
foreach($row as $k=>$value){
$array[$i][$fields[$k]] = $value;
}
$i++;
}
if(!feof($handle)){
echo "Error: unexpected fgets() fail
";
}
fclose($handle);
}
print_r($array);