Re: foreach
| From: | Jo�o C�ndido de Souza Neto | Date: | Tue, 10 Oct 2006 21:09:37 +0000 |
| Subject: | Re: foreach | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-242969@lists.php.net to get a copy of this message | ||
Thanks for your tip, but unfortunately it wouldn´t help me.
""Richard Lynch"" <ceo@l-i-e.com> escreveu na mensagem
news:11949.208.195.234.254.1160514069.squirrel@www.l-i-e.com...
> 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?