I read some csv file and map the contents to the field names using array_combine:
$csv = array();
$a = array('some fields');
$b = array_combine($a, $csv);
However if the field names in $a are different from what I specified in my csv file the method will fails with a warning
array_combine()
[function.array-combine]: Both
parameters should have an equal number
of elements
I tried using try and catch but this does not work. As a note, I am working with zend framework.
Any ideas how to catch the warning?
Grab the number of columns in the CSV and then compare it to
$a‘s length. Since you didn’t specify, I’ll assume the array is one dimensional with each line from the CSV file.