[Phpwm] foreach

David Goodwin david at codepoets.co.uk
Mon Dec 11 15:12:24 GMT 2006


Greg Jones wrote:
> Not quite sure I understand, but my best guess would be 'no'. is the
> 'break' construct perhaps what you're after?
> 
> http://uk.php.net/break
> 


Alternatively, you could use while, next, each and do manual array 
iteration, e.g.

while(!$found && list($key, $value) = each($thearray)) {
     if($value == $whatever) {
         $found = true;
     }
     next($thearray);
     ....
}



As Jake suggested, break is far cleaner :

foreach($myarray as $key => $value) {
     if($value == $whatever) {
          break;
     }
     ....
}


(My syntax may be wrong.... I've not checked it... )

David.



More information about the Phpwm mailing list