Tuesday 1 June 2021

array shift after export pdf array (col header, value row)

 Shift off the first item to get the keys:

$keys = array_shift($array);

Then map array_combine over the rest of it using the array of keys.

$result = array_map(function($values) use ($keys) {
    return array_combine($keys, $values); }, $array);

Based on the code shown in your edit, it looks like you could actually do this as you build the array instead if you replace $rows[] = $cells; with:

if (isset($keys)) {
$rows[] = array_combine($keys, $cells);
} else {
$keys = $cells;
}

No comments:

Post a Comment