Search code examples
phparrayscsv-import

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


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.


Solution

  • Use array_shift :

    array_shift($csv);