Maison >développement back-end >tutoriel php >PHP函数continue在循环结构中的用法_PHP教程
我们在实际的PHP函数continue与众不同之处在于接受一个可选的数字参数来决定跳过几重循环到循环结尾。
在php中,continue 在循环结构中用来跳过本次循环中剩余的代码并开始执行下一次循环。这一点和其他语言是一致的,不过,另有妙处:continue 接受一个可选的数字参数来决定跳过几重循环到循环结尾。
<ol class="dp-xml"> <li class="alt"><span><span>#php_continue.php </span></span></li> <li class=""><span> </span></li> <li class="alt"> <span>$</span><span class="attribute"><font color="#ff0000">i</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">0</font></span><span>; </span> </li> <li class=""> <span>$</span><span class="attribute"><font color="#ff0000">j</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">0</font></span><span>; </span> </li> <li class="alt"> <span>while ($i++ </span><strong><font color="#006699"><span class="tag"><span class="tag-name">3</span></span></font></strong><span>) {//level 3 </span> </li> <li class=""><span>echo "Outer </span></li> <li class="alt"><span>n"; </span></li> <li class=""><span>while (1){//level 2 </span></li> <li class="alt"><span>echo "Middle </span></li> <li class=""><span>n"; </span></li> <li class="alt"><span>while (1){//level 1 </span></li> <li class=""><span>echo "Inner </span></li> <li class="alt"><span>n"; </span></li> <li class=""><span>continue 3; </span></li> <li class="alt"><span>} </span></li> <li class=""><span>echo "Thisnever gets output. </span></li> <li class="alt"><span>n"; </span></li> <li class=""><span>} </span></li> <li class="alt"><span>echo"Neither does this. </span></li> <li class=""><span>n"; </span></li> <li class="alt"><span>$j++; </span></li> <li class=""><span>//after runscontinue 3,it comes to the end of level 3 </span></li> <li class="alt"><span>} </span></li> <li class=""> <span>echo"$</span><span class="attribute"><font color="#ff0000">j</font></span><span>=$j";//output: $</span><span class="attribute"><font color="#ff0000">j</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">0</font></span><span> </span> </li> <li class="alt"> <span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span> </li> </ol>
以上这段代码,就是PHP函数continue的具体用法,希望对大家有所帮助。