怎么在PHP循环结构中使用continue函数

本篇文章给大家分享的是有关怎么在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";  }  echo"Neither does this.  \n";  $j++;  //after runscontinue 3,it comes to the end of level 3  }  echo"\$j=$j";//output: $j=0 ?>

以上就是怎么在PHP循环结构中使用continue函数,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。