On Tue, 10 Oct 2006 14:34:54 -0400, John Nichel wrote:

> Chris Boget wrote:
>>> $last = end ( $numbers );
>>> reset ( $numbers );
>> 
>> I thought foreach() already performed a reset()?  Why do it again here?
>> 
> 
> Well, corn my fritters, according to TFM, it does this indeed.  Maybe an 
> old dog can learn new tricks.  ;)

Actually, foreach() creates a copy of the mentioned array, and the array
pointer of the original array is not modified. Very useful to know if you
append entries to the array you're foreach()-ing and pulling your hair out
why foreach() doesn't iterate through those new entries...

An way of going through the array independent of the actual values (since
using end() relies on unique values):

$n = count($numbers);
$i = 0;
foreach ($numbers as $number) {
    $i ++;
    if ($i == $n) {
        // Last element...
    } else {
        // Not the last element...
    }
}

Ivo

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

Reply via email to