continue: continue 在循环结构用用来跳过本次循环中剩余的代码并开始执行下一次循环.
注: 注意在 php 中 switch 语句被认为是作为 continue 目的的循环结构.continue 接受一个可选的数字参数来决定跳过几重循环到循环结尾.
<?php while (list( $key , $value ) = each( $arr )) { if ( $key == "zhoz" ){ // 如果查询到对象的值等于zhoz,这条记录就不会显示出来了。 continue ; } do_something ( $value ); } //例子2 foreach ( $list as $temp ) { if ( $temp ->value == "zhoz" ) { continue ; // 如果查询到对象的值等于zhoz,这条记录就不会显示出来了。 } do_list; // 这里显示数组中的记录 } ?>break: break 结束当前 for,foreach,while,do..while 或者 switch 结构的执行,break 可以接受一个可选的数字参数来决定跳出几重循环.
<?php $arr = array ( 'one' , 'two' , 'three' , 'four' , 'stop' , 'five' ); while (list (, $val ) = each ( $arr )) { if ( $val == 'stop' ) { break ; /* you could also write 'break 1;' here. */ } echo "$val<br>n" ; } /* using the optional argument. */ $i = 0; while (++ $i ) { switch ( $i ) { case 5: echo "at 5<br>n" ; break 1; /* exit only the switch. */ case 10: echo "at 10; quitting<br>n" ; break 2; /* exit the switch and the while. */ default : break ; } } ?>实例二:
<?php $i = 0; while ( $i < 7) { if ( $arr [ $i ] == "stop" ) { break ; } $i ++; } ?>查看更多关于php continue和break流程控制语名用法的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did26976