PHP函数continue在循环结构中的用法
我们在实际的
PHP函数continue与众不同之处在于接受一个可选的数字参数来决定跳过几重循环到循环结尾。
在php中,continue 在循环结构中用来跳过本次循环中剩余的代码并开始执行下一次循环。这一点和其他语言是一致的,不过,另有妙处:continue 接受一个可选的数字参数来决定跳过几重循环到循环结尾。
- #php_continue.php
- $i = 0;
- $j = 0;
- while ($i++ <3) {//level 3
- echo Outer
- n;
- while (1){//level 2
- echo Middle
- n;
- while (1){//level 1
- echo Inner
- n;
- continue 3;
- }
- echo Thisnever gets output.
- n;
- }
- echoNeither does this.
- n;
- $j++;
- //after runscontinue 3,it comes to the end of level 3
- }
- echo$j=$j;//output: $j=0
- ?>
以上这段代码,就是PHP函数continue的具体用法,希望对大家有所帮助。
本文链接:http://www.phprm.com/frame/php1003611.html
收藏随意^^请保留教程地址.