Re: Split()

From: Date: Wed, 18 Feb 2004 03:28:34 +0000
Subject: Re: Split()
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-178048@lists.php.net to get a copy of this message
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


« previous php.general (#178048) next »