[thelist] PHP String Indexed Arrays

Warden, Matt mwarden at mattwarden.com
Fri Jun 7 00:58:01 CDT 2002


On Jan 1, Jacob Aust had something to say about [thelist] PHP String...

>Hi...
>
>I'm somewhat of a beginner in PHP and I have been beating my head against
>this one today.
>
>I have a string indexed array that I am stepping through and formatting with
>HTML. I am trying to figure out a way to find out when I am at the last item
>in the array. My loop writes the value of each element and then inserts a
>slash for separation from the next element. However, after the last item I
>want to not output the slash.
>
>Is it possible to referenct items in a string indexed array by a numeric
>index? I can easily get the number of items in the array with count(), but
>how do I tell if the current item in a foreach() loop is the last one?

try this inside your foreach loop:

if ( !(array[item] == end(array)) )
{
	print "/";
}
else
{
	// currently on the last element
}


hth,


--
mattwarden
mattwarden.com




More information about the thelist mailing list