Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Looping over multiple multidimensional associative arrays

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
glynnyth
Smarty n00b


Joined: 18 Sep 2006
Posts: 1

PostPosted: Mon Sep 18, 2006 2:47 pm    Post subject: Looping over multiple multidimensional associative arrays Reply with quote

{foreach}: only for single array (says manual), non-numeric arrays allowed at every level (i.e. associative arrays of associative arrays)
{section}: iteration over multiple arrays, but non-numeric arrays only allowed at lowest level (i.e. indexed arrays of associative array)

How to iterate over multiple multidimensional associative arrays of associative arrays?

$test = array("foo"=>array("AA"=>array("bel"=>0, "eur"=>1, "europ"=>2, "am"=>3,"az"=>4,"glob"=>5)));
$test2 = array("foo"=>array("AA"=>array("bel"=>0, "eur"=>1, "europ"=>2, "am"=>3,"az"=>4,"glob"=>5)));

***

{foreach from=$test key=key item=item}
Array1: {$stats.AA.am} = {$test.$key.AA.am}
Array2: {$test2.$key.AA.am}
{/foreach}

'item' is not used but required by Smarty
keys of arrays need to be the same
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Sep 18, 2006 4:39 pm    Post subject: Reply with quote

Code:
{foreach from=$test key="key1" item="val1"}
  {foreach from=$val1 key="key2" item="val2"}
    {foreach from=$val2 key="key3" item="val3"}
       ...
    {/foreach}
  {/foreach}
{/foreach}
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP