In PHP, I want to read a ".CSV" file using the following function.
function csv_to_array($filename='a.txt', $header_exist=true, $delimiter="\t")
{
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_exist)
{
if(!$header)
$header = array_map('trim', $row);
else
$data[] = array_combine($header, $row);
}
else
$data[] = $row;
}
fclose($handle);
}
return $data;
}
and I am bit confused about array_map()
function. I think it is supposed to map column names to each attribute is that so then how to fetch and display eacg attribute?
Thank you!