您的位置:首页 > 编程语言 > PHP开发

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

2013-09-04 21:48 281 查看
我们在实际的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的具体用法,希望对大家有所帮助。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  PHP函数 函数