时间:2021-07-01 10:21:17 帮助过:18人阅读
注: 注意在 php教程 中 switch 语句被认为是作为 continue 目的的循环结构。
continue 接受一个可选的数字参数来决定跳过几重循环到循环结尾。
<?php
while (list($key,$value) = each($arr))
{
if ($key == "zhoz")
{
// 如果查询到对象的值等于zhoz,这条记录就不会显示出来了。
continue;
}
do_something ($value);
}例子2
<?php
foreach ($list as $temp)
{
if ($temp->value == "zhoz")
{
continue;
// 如果查询到对象的值等于zhoz,这条记录就不会显示出来了。
}
do_list;
// 这里显示数组中的记录
}break
break 结束当前 for,foreach,while,do..while 或者 switch 结构的执行。
break 可以接受一个可选的数字参数来决定跳出几重循环。
<?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;
}
}
?>实例二
<?php
$i = 0;
while ($i < 7)
{
if ($arr[$i] == "stop")
{
break;
}
$i++;
}
?>以上就是php基础流程控制语句continue和break用法的详细内容,更多请关注Gxl网其它相关文章!