Dr. Professor
Dr. Professor

Reputation: 63

How to itearate foreach loop in smarty as key maps to val in php

I am trying to use foreach loop in smarty after assigning an associative array with unordered keys but it is not working. I need both the keys and the values. How do I do this.

The assigned array :

$arr[34] = 'Profile';
$arr[70] = 'Logo';
$arr[300] = 'Items';

$this->assign('arr', $arr);

Upvotes: 0

Views: 649

Answers (1)

Bjoern
Bjoern

Reputation: 16304

Have a look at foreach.

Example, adjusted to your array:

<ul>
{foreach $arr as $keyvar=>$itemvar}
    <li>Key {$keyvar} : {$itemvar} </li>
{/foreach}
</ul>

The Smarty manual has some more examples to help you further if needed.

Upvotes: 1

Related Questions