이 코드는 제가 찾고있는 결과를 제공합니다. 멋지게 형식화 된 값 트리입니다.PHP 코드는 함수가 될 때까지 작동합니다.
$todos = $this->db->get('todos'); //store the resulting records
$tree = array(); //empty array for storage
$result = $todos->result_array(); //store results as arrays
foreach ($result as $item){
$id = $item['recordId'];
$parent = $item['actionParent'];
$tree[$id] = isset($tree[$id]) ? $item + $tree[$id] : $item;
$tree[$parent]['_children'][] = &$tree[];
}
echo '<pre>';
print_r($tree);
echo '</pre>';
foreach의 코드를 이와 같이 함수에 넣으면 빈 배열이 생깁니다. 내가 뭘 놓치고 있니?
function adj_tree($tree, $item){
global $tree;
// ...
또는
function adj_tree(&$tree, $item){
그렇게 했으니까요. – Chris