Currently, the function creates a local copy of {$ tree}, editing it, and then discarding that copy when the function closes.
You have two options:
1) return the local copy of {$ tree} and assign it to the global copy.
function adj_tree($tree, $item){
$id = $item['recordId'];
$parent = $item['actionParent'];
$tree[$id] = isset($tree[$id]) ? $item + $tree[$id] : $item;
$tree[$parent]['_children'][] = &$tree[];
return $tree;
}
foreach ($result as $item){
$tree = adj_tree($tree, $item);
}
2) pass the array by reference and edit the global version inside the function.
function adj_tree(&$tree, $item){
$id = $item['recordId'];
$parent = $item['actionParent'];
$tree[$id] = isset($tree[$id]) ? $item + $tree[$id] : $item;
$tree[$parent]['_children'][] = &$tree[];
}
source
share