Adam Bregenzer wrote:

On Tue, 2004-02-17 at 15:22, Jochem Maas wrote:

$applePie = array(1,2,3,4,5,6,7,8);

while ($pieceOfPie = array_shift($applePie)) {
        echo $pieceOfPie; // want some pie?
}


Careful, that will eat your array as well.  When the while loop finishes
you won't have any pieces of pie left!

that was the idea: you can't have your pie at eat it right? ;-)


seriously thought, John Taylor-Johnston was asking for help on while loops and I thought I'd give him some brainfood (i.e. a little optimalization thrown in). besides which how many times have we in our PHP
careers not created arrays just to loop over them once, outputting each item?



IE: $applePie = array(1,2,3,4,5,6,7,8);

while ($pieceOfPie = array_shift($applePie)) {
        echo $pieceOfPie; // want some pie?
}

// Both of these are now true:
$applePie == array();
$applePie != array(1,2,3,4,5,6,7,8);

-Adam


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



Reply via email to