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

Double multi-dimensional arrays..or something

 
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 -> General
View previous topic :: View next topic  
Author Message
lennert
Smarty n00b


Joined: 26 Aug 2003
Posts: 1

PostPosted: Tue Aug 26, 2003 1:05 pm    Post subject: Double multi-dimensional arrays..or something Reply with quote

How to do this? I have two arrays, each value in the 2nd array is an associative array with, among others, keys called 'myname'. For instance, $arr2[0].myname contains 'blah'. The result is used as an index for the array value of the first array, e.g. $arr1[2].blah.

But this doesn't work:

{section name=x loop=$arr1}
{section name=y loop=$arr2}
{$arr1[x].$arr2[y].myname
{/section}
{/section}
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Aug 26, 2003 1:29 pm    Post subject: Reply with quote

This comes up every so often. The problem is that Smarty doesn't resolve {$arr1[x].$arr2[y].myname} the way you think it does. What you need to do is make an intermediate assignment to capture the index key:
Code:
{section name=y loop=$arr2}
  {assign var=index value=$arr2[y].myname}
  {$arr1[y].$index}
{/section}

I wasn't sure why you used two loops, so I removed one. I'm assuming that for each $arr1[n] there is a corresponding $arr2[n] and vice-versa.

HTH
Back to top
View user's profile Send private message
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 -> General 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