标签:json reac func enc encode code pre cat foreach
function ad(){
$res=DB::table("category")->get();
$res= json_encode($res);
$res= json_decode($res,1);
$arr= $this->gettree($res,0);
var_dump($arr);
}
function gettree($data,$pid){
$tree=[];
foreach ($data as $k=>$v){
if ($v[‘pid‘]==$pid){
$v[‘son‘]=$this->gettree($data,$v[‘id‘]);
$tree[]=$v;
}
}
return $tree;
}
标签:json reac func enc encode code pre cat foreach
原文地址:https://www.cnblogs.com/azzy/p/11748746.html