Ignore header/comments reading CSV with array_map() and str_getcsv() as the callback

810 views Asked by At

Is there a method to ignore header/comments when using the following PHP method combination:

$csv = array_map('str_getcsv', file('file.csv'));

Example CSV

date, val1, val2, val3
2014-12-2, 1, 4, 5 
2014-12-3, 2, 1, 3 
2014-12-4, 2, 0, 1

I'd like $csv[0][0] to equal 2014-12-2, etc.

1

There are 1 answers

2
toto21 On BEST ANSWER

Use array_shift :

array_shift($csv);