Reputation: 63
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
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