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的作用的具体内容,更多请存眷资源魔其它相干文章!
标签: php php开发教程 php开发资料 php开发自学 break
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。