$mylist = array(array( 'parent_id'=>0,'id'=>1),
array( 'parent_id'=>0,'id'=>2),
array( ' parent_id'=>0,'id'=>3),
array( 'parent_id'=>2,'id'=>4),
array( 'parent_id'=>2,'id' =>5),
array( 'parent_id'=>3,'id'=>6),
array( 'parent_id'=>3,'id'=>7),
array( ' parent_id'=>4,'id'=>8),
array( 'parent_id'=>5,'id'=>9),
array( 'parent_id'=>5,'id' =>10)
);
function _findChildren($list, $p_id){ //数据层级化,
$r = array();
foreach($list as $id=>$item){
if($item['parent_id'] == $p_id) {
$length = count($r);
$r[$length] = $item;
if($t = $this->_findChildren($list, $item['id'] ) ){
$r[$length]['children'] = $t;
}
}
return $r;
}
print_r(_findChildren($mylist, 0));