数组是
`Array
(
[0] => Array
(
[id] => 1
[pid] => 0
[name] => 安徽省
[son] => Array
(
[0] => Array
(
[id] => 3
[pid] => 1
[name] => 合肥市
[son] => Array
(
[0] => Array
(
[id] => 4
[pid] => 3
[name] => 长丰县
)
)
)
[1] => Array
(
[id] => 5
[pid] => 1
[name] => 安庆市
)
)
)
[1] => Array
(
[id] => 2
[pid] => 0
[name] => 浙江省
)
)`
然后我把他们列出来 很傻瓜的写法 只能输出三级循环
foreach(上面的数组 as $row)
{ echo $row['id'];
echo $row['name'];
if(isset($row['son'])){
foreach($row['son'] as $k => $v){
echo $v['id'];
echo $v['name'];
if(isset($v['son'])){
foreach($v['son'] as $m => $n){
echo $n['id'];
echo $n['name'];
}
}
}
}
}
这样写效率不好吧?
如何简化写法?或者无限循环。。。
黄舟2017-04-10 16:05:14
骚年,凡事先搜索,学会自己解决问题。
5行代码不递归解决无限分类:http://www.oschina.net/code/snippet_173183_11767