Re: foreach

From: Date: Tue, 10 Oct 2006 21:01:09 +0000
Subject: Re: foreach
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-242938@lists.php.net to get a copy of this message
On Tue, October 10, 2006 1:14 pm, João Cândido de Souza Neto wrote: > $numbers=array(1,2,3,4,5); > foreach ($numbers as number) { > ... > } > > Inside foreach, could i know if i am in the last element of the array > $numbers? In general, you can't. If the elements are unique, you could do: $last = end($numbers); ... if ($last == $number) "this is the end"; Most people who want this "feature" are trying to suppress outputting a comma or other separator after the last item because they have not yet figured out how to use this function: http://php.net/implode -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?

« previous php.general (#242938) next »