程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> PHP函數continue在循環結構中的用法

PHP函數continue在循環結構中的用法

編輯:關於PHP編程

我們在實際的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. echo"Neither 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的具體用法,希望對大家有所幫助。


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved