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