function addParent($array, $parent = null) {
foreach ($array as $key => $value) {
if (\is_null($parent)) {
$array[$key]['category'] = addParent($value['category'], $value['@attributes']['code']);
$array[$key]['@attributes'] = $value['@attributes'];
} else {
$array[$key]['code_parent'] = $parent;
}
}
return $array;
}
multimap($arr);
function multimap($array, $level = 0) {
$result = [];
foreach ($array as $key => $data) {
foreach ($data as $inner) {
$result[$key] = [
'id' => $inner['@attributes']['id'],
'name' => $inner['@attributes']['name']
];
if ($level == 0) {
$result[$key]['parent'] = $inner['@attributes']['parent'];
}
unset($inner['@attributes']);
$result = \array_merge($result, multimap($inner, $level+1));
}
}
return $result;
}