note 90323 added to control-structures.foreach
| From: | NikolayErmolenko at osu1 dot php dot net | Date: | Thu, 16 Apr 2009 12:58:36 +0000 |
| Subject: | note 90323 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153382@lists.php.net to get a copy of this message | ||
Using continue and break:
<?php
$stack = array('first', 'second', 'third', 'fourth',
'fifth');
foreach($stack AS $v){
if($v == 'second')continue;
if($v == 'fourth')break;
echo $v.'<br>';
}
/*
first
third
*/
$stack2 = array('one'=>'first', 'two'=>'second',
'three'=>'third', 'four'=>'fourth',
'five'=>'fifth');
foreach($stack2 AS $k=>$v){
if($v == 'second')continue;
if($k == 'three')continue;
if($v == 'fifth')break;
echo $k.' ::: '.$v.'<br>';
}
/*
one ::: first
four ::: fourth
*/
?>
----
Server IP: 78.41.104.4
Probable Submitter: 83.137.219.66
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/90323
Del: integrated -- https://master.php.net/note/delete/90323/integrated
Del: useless -- https://master.php.net/note/delete/90323/useless
Del: bad code -- https://master.php.net/note/delete/90323/bad+code
Del: spam -- https://master.php.net/note/delete/90323/spam
Del: non-english -- https://master.php.net/note/delete/90323/non-english
Del: in docs -- https://master.php.net/note/delete/90323/in+docs
Del: other reasons-- https://master.php.net/note/delete/90323
Reject -- https://master.php.net/note/reject/90323
Search -- https://master.php.net/manage/user-notes.php