欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

smarty 怎么在模板上循环遍历输出三维数据???

程序员文章站 2024-01-29 15:39:58
...
smarty php 多维数组循环 这个从php传过来的数组结构。

Array
(
[0] => Array
(
[0] => Array
(
[id] => 15
[pid] => 0-2-11
[name] => 女装
[href] =>
[date] =>
)

[1] => Array
(
[id] => 18
[pid] => 0-2-11
[name] => 衬衣
[href] =>
[date] =>
)

[2] => Array
(
[id] => 40
[pid] => 0-2-11
[name] => www
[href] =>
[date] =>
)

[3] => Array
(
[id] => 45
[pid] => 0-2-11
[name] => 费共和
[href] =>
[date] =>
)

)

[1] => Array
(
)

[2] => Array
(
[0] => Array
(
[id] => 43
[pid] => 0-2-13
[name] => 呃呃
[href] =>
[date] =>
)

)

[3] => Array
(
)

[4] => Array
(
)

[5] => Array
(
)

[6] => Array
(
)

[7] => Array
(
[0] => Array
(
[id] => 41
[pid] => 0-3-16
[name] => 呜呜呜
[href] =>
[date] =>
)

)

[8] => Array
(
[0] => Array
(
[id] => 44
[pid] => 0-3-21
[name] => 阿斯顿
[href] =>
[date] =>
)

)

[9] => Array
(
)

[10] => Array
(
)

[11] => Array
(
)

[12] => Array
(
[0] => Array
(
[id] => 42
[pid] => 0-9-38
[name] => 高交会馆
[href] =>
[date] =>
)

)

)

回复讨论(解决方案)

smarty foreach

smarty foreach
这个我知道,但是三维数组不会弄!

要的这种效果

要的这种效果


{foreach item=lop key=k name=loop from=$dao}              
  • {$dao[$k].name} {foreach item=lop2 key=kk name=loop1 from=$dao1} { if $k==$kk && $dao1[$kk]|@count neq 0}
      {foreach item=lop3 key=kkk from=$lop2}
    • {$lop3.name} {foreach item=lop4 key=kkkk from=$dao2} {if $dao2[$kkk]|@count neq 0} {foreach item=lop5 name=app key=kkkkk from=$lop4} {if $lop5.pid===$lop3.pid|cat:"-"|cat:$lop3.id} {if $smarty.foreach.app.index==0}
        {/if}
      • {$lop5.name}
      • {if $smarty.foreach.app.iteration==$lop4|@count}
      {/if} {/if} {/foreach} {/if} {/foreach}
    • {/foreach}
    {/if} {/foreach}
  • {/foreach}