- array_replace_recursive: documentation ( source)
- json_encode: documentation ( source)
<?php
function shortenedRecursiveExport(&$data, $depth = 0) {
foreach ($data as $key => $value) {
if (is_array($value)) {
shortenedRecursiveExport($data[$key], $depth + 1);
}
}
}
$data = [
['k' => [0, 1]],
['k' => [2, 3]],
];
echo 'pre: ' . json_encode($data) . "\n";
shortenedRecursiveExport($data);
array_replace_recursive($data[0], $data[1]);
echo 'post: ' . json_encode($data) . "\n";