tete

nameP == $root) { $item = array('name' => $obj->name); if ($children = recur222($flat, $obj->nameP)) { $item['children'] = $children; } $result[] = $item; } } return $result; } $arrM1 = array(); $arrM1 []= (object)array("name"=>'n1',"nameP"=> '' ); $arrM1 []= (object)array("name"=>'n2',"nameP"=> 'n1' ); $arrM1 []= (object)array("name"=>'n3',"nameP"=> 'n2' ); $arrM1 []= (object)array("name"=>'n4',"nameP"=> 'n1' ); $tree=recur222($arrM1); //print_r($tree); ?>.