Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Get non sequential array index

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
Viskop
Smarty Rookie


Joined: 06 Jul 2004
Posts: 6
Location: South Africa

PostPosted: Tue Jul 06, 2004 1:30 pm    Post subject: Get non sequential array index Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Jul 06, 2004 1:39 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Viskop
Smarty Rookie


Joined: 06 Jul 2004
Posts: 6
Location: South Africa

PostPosted: Wed Jul 07, 2004 9:24 am    Post subject: Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Jul 07, 2004 10:25 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Viskop
Smarty Rookie


Joined: 06 Jul 2004
Posts: 6
Location: South Africa

PostPosted: Wed Jul 07, 2004 10:45 am    Post subject: Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Jul 07, 2004 11:11 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Viskop
Smarty Rookie


Joined: 06 Jul 2004
Posts: 6
Location: South Africa

PostPosted: Wed Jul 07, 2004 12:16 pm    Post subject: Reply with quote

Great stuff

Many Thanks again.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development 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