Re: foreach

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for your tip, but unfortunately it wouldn´t help me.


""Richard Lynch"" <ceo@xxxxxxxxx> escreveu na mensagem 
news:11949.208.195.234.254.1160514069.squirrel@xxxxxxxxxxxxxxxx
> 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? 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux