Forums / Developer / Access two elements of an array

Access two elements of an array

Author Message

Jorge estévez

Monday 15 May 2006 6:49:12 pm

I would like to loop an array and build an html code.

My array contanis always multiple of 2 objects (2,4,6,8... etc), all of them being images (class image)

In an array of 8 elements, element 1 of the array is always linked to number 5, thus 2 is linked to 6, 3 is linked to 7 and 4 is linked to 8 (when I say linked I mean they are related in someway)

I would like to loop the array (only half the amount of items inside it, in this example 4), and access within the loop object 1 and 5, 2 and 6, 3 and 7, 4 and 8.

So within one loop I DO NOT KNOW how to access different indexes of the array.

Here is the pseudo-code, asume we are accessing the first element of the array,




{section var=child loop=$list_items}

<a onmouseover="return showPic(this)" 
	href="INSERT THE URL OF ELEMENT 5">
												
	VISUALIZE IMAGE OF ELEMENT 1
</a>

{/section}

any help, please...

thanks

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

Nicolas Ottavi

Tuesday 16 May 2006 3:37:03 am

Hi,

With a foreach you can access the index, and then after that you could be able to do what you want.

{foreach $list_item as $index => $item}
...
{/foreach}

Regards,
Nicolas

Jorge estévez

Tuesday 16 May 2006 4:31:54 am

Can you be more specific?

How to access a object of an array Array(index).name, Array[index].name ?

I need to access attributes of an element of the array, so index plays an important role as well as the attribute I whant to access, just cant the code working...

thanks

Diseño Web Cuba
Web Design Cuba
www.elfosdesign.com

Nicolas Ottavi

Friday 19 May 2006 3:59:18 am

Hi,

{$array.0} {* return first element of an array *}
{$array.$index} {* return element at $index position *}

Hope it helps,
Nicolas