【www.gdgbn.com--php常用代码】

continue
continue 在循环结构用用来跳过本次循环中剩余的代码并开始执行下一次循环。

注: 注意在 php教程 中 switch 语句被认为是作为 continue 目的的循环结构。

continue 接受一个可选的数字参数来决定跳过几重循环到循环结尾。

 

while (list($key,$value) = each($arr)) {
if ($key == "zhoz"){ // 如果查询到对象的值等于zhoz,这条记录就不会显示出来了。
continue;
}
do_something ($value);
}
//  例子2
foreach ($list as $temp) {
if ($temp->value == "zhoz") {
continue; // 如果查询到对象的值等于zhoz,这条记录就不会显示出来了。
}
do_list; // 这里显示数组中的记录
}
?>

break
break 结束当前 for,foreach,while,do..while 或者 switch 结构的执行。

break 可以接受一个可选的数字参数来决定跳出几重循环。

$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
n";
}

/* using the optional argument. */

$i = 0;
while (++$i) {
   switch ($i) {
   case 5:
       echo "at 5
n";
       break 1;  /* exit only the switch. */
   case 10:
       echo "at 10; quitting
n";
       break 2;  /* exit the switch and the while. */
   default:
       break;
   }
}
?>

实例二

 

$i = 0;
while ($i < 7) {
if ($arr[$i] == "stop") {
break;
}
$i++;
}
?>

本文来源:http://www.gdgbn.com/jiaocheng/29933/