开发者

Smarty: multidimensional array

I need to loop 开发者_如何转开发into a multidimensional array in smarty and {section} is giving me a hard time

This is the array called $brands:

Array (26)
    A => Array (4)
      0 => "Alienation"
      1 => "Alligator"
      2 => "Amoeba"
      3 => "Animal"
    B => Array (2)
      0 => "Bell"
      1 => "Bontrager"
    C => Array (9)
      0 => "Camicleta"
      1 => "Cannondale"
      2 => "Cateye"
      3 => "Coach"
      4 => "Colner"
      5 => "Continental"
      6 => "Crankbrothers"
      7 => "Cratoni"
      8 => "CST"
    D => Array (7)
      0 => "Da Bomb"
      1 => "Deli"
      2 => "Demolition"
      3 => "Diadora"
      4 => "Diamondback"
      5 => "DNM"
      6 => "DT Swiss"
    E => Array (3)
      0 => "Eastman"
      1 => "Easton"
      2 => "Eighties"
    ...

I want to output

<h2>A</h2>
      Alienation
      Alligator
      Amoeba
      Animal
<h2>B</h2>
      Bell
      Bontrager
....

And so one

I understand I should iterate twice inside the brands array, but can't get it to work


Try using a nested foreach:

{foreach from=$myArr key=key item=item}
    <h2>{$key}</h2>
    {foreach from=$item item=i}
        {$i} <br />
    {/foreach}
{/foreach}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜