Rumah >pembangunan bahagian belakang >tutorial php >PHP数组无限分级数据的层级化处理代码_PHP教程
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));