function csv_multiline_to_array
Search API
7.x misc.inc | csv_multiline_to_array($csv_str, $bool_first_row_is_headers = TRUE) |
6.x misc.inc | csv_multiline_to_array($csv_str, $bool_first_row_is_headers = TRUE) |
From https://www.php.net/manual/en/function.str-getcsv.php#117692
File
- includes/
misc.inc, line 1804 - This file contains misc functions for FlightPath
Code
function csv_multiline_to_array($csv_str, $bool_first_row_is_headers = TRUE) {
$csv = array_map('str_getcsv', explode("\n", trim($csv_str)));
array_walk($csv, function(&$a) use ($csv) {
if (count($a) == count($csv [0])) {
$a = array_combine($csv [0], $a);
}
else {
fpm("Warning: issue converting multiline CSV to an array within FlightPath. Not the same number of elements.");
}
});
if (!$bool_first_row_is_headers) {
array_shift($csv); # remove column header
}
return $csv;
}