continue
continue The loop structure is used to skip the remaining code in this loop and start executing the next loop.
Note: Note that in php tutorial the switch statement is considered a loop structure for continue purposes.
continue accepts an optional numeric parameter to determine how many loops to skip to the end of the loop.
<?php while (list($key,$value) = each($arr)) { if ($key == "zhoz") { // 如果查询到对象的值等于zhoz,这条记录就不会显示出来了。 continue; } do_something ($value); }
Example 2
<?php foreach ($list as $temp) { if ($temp->value == "zhoz") { continue; // 如果查询到对象的值等于zhoz,这条记录就不会显示出来了。 } do_list; // 这里显示数组中的记录 }
break
break ends the execution of the current for, foreach, while, do..while or switch structure.
break can accept an optional numeric parameter to determine how many loops to break out of.
<?php $arr = array ('one', 'two', 'three', 'four', 'stop', 'five'); while (list (, $val) = each ($arr)) { if ($val == 'stop') { break; /* you could also write 'break 1;' here. */ } echo "$val<br>n"; } /* using the optional argument. */ $i = 0; while (++$i) { switch ($i) { case 5: echo "at 5<br>n"; break 1; /* exit only the switch. */ case 10: echo "at 10; quitting<br>n"; break 2; /* exit the switch and the while. */ default: break; } } ?>
Example 2
<?php $i = 0; while ($i < 7) { if ($arr[$i] == "stop") { break; } $i++; } ?>
The above is the detailed content of PHP basic process control statements continue and break usage. For more information, please follow other related articles on the PHP Chinese website!