Re: foreach

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

 



João Cândido de Souza Neto wrote:
Hello.

In the follow code:

$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?


$last = end ( $numbers );
reset ( $numbers );
foreach ( $numbers as $number ) {
	if ( $number == $last ) {
		// last element
		...
	}
	....
}

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
jnichel@xxxxxxxxxxxxxxxxxxxxxxxxxxx

--
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