Categories
PHP

CSV to Array in PHP

I found on PHP.net this super short way of doing this:

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

But was not working good for us since was not taking the delimiters properly, and not escaping good.

So I did a simple function to convert a CSV file to an Array, it can validate the header to be sure has the correct format. Also allows to return an array with objects.