views:

25

answers:

1

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

+1  A: 

Try using a nested foreach:

{foreach from=$myArr key=key item=item}
    <h2>{$key}</h2>
    {foreach from=$item item=i}
        {$i} <br />
    {/foreach}
{/foreach}
karim79
Worked like a charm, Thanks!
The Disintegrator