php中用foreach()循环中,想要在循环的时候,当满足某个条件时,想要跳出本次循环继续执行下次循环,或者满足某个条件的时候,终止foreach()循环,分别会用到:continue 与 break
<?php
$arr= array('le','yang','jun','lecode','gagade');
$html= '';
foreach($arras $key => $value){
if($value=='b'){
$html.= $value;
continue;// 当 $value为b时,跳出本次循环
}
if($value=='c'){
$html.= $value;
break;// 当 $value为c时,终止循环
}
$html.= $value;
}
echo$html; // 输出: abc
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号