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 Answer 1

1

Try using a nested foreach:

{foreach from=$myArr key=key item=item}
    <h2>{$key}</h2>
    {foreach from=$item item=i}
        {$i} <br />
    {/foreach}
{/foreach}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.