- array_combine: documentation ( source)
- array_shift: documentation ( source)
- array_walk: documentation ( source)
<?php
$x = [['A','B','C'],[1,2,3],[4,5,6],[7,8,9]];
$headers = array_shift($x);
array_walk(
$x,
function(&$row) use ($headers) {
$row = array_combine($headers, $row);
}
);
$y = json_export($x,true);
echo $y;