I have a csv file thats uploaded and I need to determine how many entries are in the csv file and format the first, middle and last columns to a associative array with $header=>$value pairs. I have the code that formats the entire csv to the array
function csv_to_array($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;
}
However I am stuck as far as determining the way to do this. Any help would be appreciated. One thing that may be possible i suppose is to use this function above to get the array and then write some other function to get the beginning middle and end of this array only and dump the rest (but still need to konw how to do it as far as determining the beginning middle and end
$row=array($row[0], $row[floor(sizeof($row)/2)] ,$row[sizeof($row)-1]);