View previous topic :: View next topic |
Author |
Message |
Viskop Smarty Rookie
Joined: 06 Jul 2004 Posts: 6 Location: South Africa
|
Posted: Tue Jul 06, 2004 1:30 pm Post subject: Get non sequential array index |
|
|
Hi there
I have a array with non sequential indexes.How do you get the index considering i'm using {SECTION} for looping becuase I have more than one array involved.
$smarty.section.customer.index returns a sequential index.How do I get the array index like you would in {foreach}'s key
Any Idea? |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Jul 06, 2004 1:39 pm Post subject: |
|
|
it's simply *NOT TRUE* that you need section if more than one array is involved.
but it *IS TRUE* that you can use {section} with non sequential keys.
[edit: sorry, the second sentence is bullshit. i wanted to say:
it is *NOT TRUE* that you can use {section} with non sequential keys.]
Code: |
{foreach from=$elements item=element key=index}
$elements.$index is the same as $element
but you can also use $other_elements.$index
{/foreach}
|
Last edited by messju on Wed Jul 07, 2004 10:27 am; edited 1 time in total |
|
Back to top |
|
Viskop Smarty Rookie
Joined: 06 Jul 2004 Posts: 6 Location: South Africa
|
Posted: Wed Jul 07, 2004 9:24 am Post subject: |
|
|
Many thanks for the reply.Sorry but I'm not sure wat your getting at.
if I have 2 arrays :
$test_arr = array(3 => "three",6 => "vier");
$test_arr2 = array(3 => "three2",6 => "vier2");
I know I can use section with non sequential keys,but how do I actualy get those keys in the {section} loop
If I want to use $test_arr's keys to lookup $test_arr2's values.
Many Thanks |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Jul 07, 2004 10:25 am Post subject: |
|
|
Viskop wrote: | I know I can use section with non sequential keys,but how do I actualy get those keys in the {section} loop |
a million sorries. correct my post:
of course you *CAN NOT* use section with non sequential keys. |
|
Back to top |
|
Viskop Smarty Rookie
Joined: 06 Jul 2004 Posts: 6 Location: South Africa
|
Posted: Wed Jul 07, 2004 10:45 am Post subject: |
|
|
Thanks for reply
Comming back to the problem at hand.How does one solve this.Two array with the nested one using the outer's key.
Does one have to change your design?
Have you by chance have an example of nested {foreach} 's using 2 separate arrays
Thanks |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Jul 07, 2004 11:11 am Post subject: |
|
|
you didn't say "nested" in your first post, so i thought of parallel arrays, not nested ones. anyway, here is a nested foreach:
Code: |
{foreach from=$a1 item=outer key=outer_index}
use {$outer} here
{foreach from=$a2.$outer_index item=inner key=inner_index}
use {$inner} here
{/foreach}
{/foreach}
|
|
|
Back to top |
|
Viskop Smarty Rookie
Joined: 06 Jul 2004 Posts: 6 Location: South Africa
|
Posted: Wed Jul 07, 2004 12:16 pm Post subject: |
|
|
Great stuff
Many Thanks again. |
|
Back to top |
|
|