|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
lennert Smarty n00b
Joined: 26 Aug 2003 Posts: 1
|
Posted: Tue Aug 26, 2003 1:05 pm Post subject: Double multi-dimensional arrays..or something |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Aug 26, 2003 1:29 pm Post subject: |
|
|
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 |
|
|
|
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
|