smarty 遍历多维数组问题
本帖最后由 swordnorth 于 2013-10-21 10:10:51 编辑
Array
(
[0] => Array
(
[0] => 1
[id] => 1
[1] => 设置
[name] => 设置
[2] => 0
[parentid] => 0
[child] => Array
(
[0] => Array
(
[0] => 20
[id] => 20
[1] => 管理员管理
[name] => 管理员管理
[2] => 1
[parentid] => 1
[child] => Array
(
[0] => Array
(
[0] => 23
[id] => 23
[1] => 角色管理
[name] => 角色管理
[2] => 20
[parentid] => 20
)
[1] => Array
(
[0] => 22
[id] => 22
[1] => 管理员管理
[name] => 管理员管理
[2] => 20
[parentid] => 20
)
)
)
[1] => Array
(
[0] => 19
[id] => 19
[1] => 相关设置
[name] => 相关设置
[2] => 1
[parentid] => 1
[child] => Array
(
[0] => Array
(
[0] => 25
[id] => 25
[1] => 模型管理
[name] => 模型管理
[2] => 19
[parentid] => 19
)
[1] => Array
(
[0] => 24
[id] => 24
[1] => 菜单管理
[name] => 菜单管理
[2] => 19
[parentid] => 19
)
[2] => Array
(
[0] => 21
[id] => 21
[1] => 基本设置
[name] => 基本设置
[2] => 19
[parentid] => 19
)
)
)
)
)
<{foreach from=$arr item=m}>
ID: <{$m.id}> <{$m.name}> <{$m.id}><br>
<{foreach from=$m.child item=item}>
<{$item.name}> <{$item.id}><br>
<{foreach from=$item.child item=items}>
<{$items.name}> <{$items.id}><br>
<{/foreach}>
<{/foreach}>
<{/foreach}>
function bianli($array){
foreach($array as $value){
if(is_array($value)){
bianli($value);
}else{
echo $value."\n";
}
}
}
$a=array('A','B',array('c','d',array('e','f')),'g');
echo bianli($a);