以前写的代码,竟然看不懂了。。。。花了整整两天时间。。。。
备注一下
//功能主要是无限分级菜单
$M=M('Menu');
$condition=array('is_deleted'=>'0','status' =>'1');
$result=$M->field("id,level,pid,name")->where($condition)->order('level')->select();
//转换成数组,同级节点的索引值相同
$index[0]=0;
foreach ($result as $key => $value) {
$data[$value['level']][$key][$value['id']]=$value['name'];
$index[$value['id']]=$key;
}
//倒序将当前级添加为上级的子节点
foreach (array_reverse($data,true) as $key => $value) {
foreach ($value as $k => $v) {
$data[$key-1][$index[$result[$k]['pid']]][$k]=$data[$key][$k];
}
unset($data[$key]);
}
dump($data[0]);