I have csv values like this:
$csv_data = \"test,this,thing
hi,there,this
is,cool,dude
have,fun\";
I want
Here is a very clean and simple solution:
function parse_row($row) {
return array_map('trim', explode(',', $row));
}
$rows = str_getcsv($csv_data, "\n");
$keys = parse_row(array_shift($rows));
$result = array();
foreach ($rows as $row) {
$row = parse_row($row);
$row = array_pad($row, 3, NULL);
$result[] = array_combine($keys, $row);
}