无限极分类/数组处理
------------无限极分类--------------------
function _tree($arr,$pid=0,$val=0){
static $list=array();
foreach($arr as $v){
if($v["pid"]==$pid){
$v["val"]=$val;
$list[]=$v;
$this->_tree($arr,$v["sid"],$val+1);
}
}
return $list;
}
function _tree($arr,$pid=0,$val=0){
static $list=array();
foreach($arr as $v){
if($v["pid"]==$pid){
$v["val"]=$val;
$list[]=$v;
$this->_tree($arr,$v["sid"],$val+1);
}
}
return $list;
}
------------数组处理---------------
$data2 = array();
foreach($arr as $k=>$v){
if($v['pid'] == 0){
$data2[] = $v;
}
}
//print_R($data2);die;
foreach($data2 as $k=>$v){
foreach($arr as $kk=>$vv){
if($v['id'] == $vv['pid']){
$data2[$k]['son'][] = $vv;
}
}
}
//print_R($data2);die;
foreach($arr as $k=>$v){
if($v['pid'] == 0){
$data2[] = $v;
}
}
//print_R($data2);die;
foreach($data2 as $k=>$v){
foreach($arr as $kk=>$vv){
if($v['id'] == $vv['pid']){
$data2[$k]['son'][] = $vv;
}
}
}
//print_R($data2);die;