php中break的作用
发布时间:09/01 来源:未知 浏览:
关键词:
break 在一些运算机编程说话中是保存字,其作用大多状况下是终止所在层的轮回。在 C说话 的 switch(开关语句)中,break 语句还可用来在施行完一个 case(分支)后马上跳出当前 switch 构造。在某些程序调试历程中则使用break设定断点。下面我们就介绍一下break在PHP中的作用。
引荐教程:PHP视频教程
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中break的作用的具体内容,更多请关注百分百源码网其它相关文章!