首页 > php框架 > PHP函数continue在循环结构中的用法

PHP函数continue在循环结构中的用法

我们在实际的
PHP函数continue与众不同之处在于接受一个可选的数字参数来决定跳过几重循环到循环结尾。

在php中,continue 在循环结构中用来跳过本次循环中剩余的代码并开始执行下一次循环。这一点和其他语言是一致的,不过,另有妙处:continue 接受一个可选的数字参数来决定跳过几重循环到循环结尾。

  1. #php_continue.php  
  2.  
  3. $i = 0;  
  4. $j = 0;  
  5. while ($i++ <3) {//level 3  
  6. echo Outer  
  7. n;  
  8. while (1){//level 2  
  9. echo Middle  
  10. n;  
  11. while (1){//level 1  
  12. echo Inner  
  13. n;  
  14. continue 3;  
  15. }  
  16. echo Thisnever gets output.  
  17. n;  
  18. }  
  19. echoNeither does this.  
  20. n;  
  21. $j++;  
  22. //after runscontinue 3,it comes to the end of level 3  
  23. }  
  24. echo$j=$j;//output: $j=0 
  25. ?> 

以上这段代码,就是PHP函数continue的具体用法,希望对大家有所帮助。


本文链接:http://www.phprm.com/frame/php1003611.html

收藏随意^^请保留教程地址.

标签:none

发表留言