PHP中用foreach()循环中,想要在循环的时候,当满足某个条件时,想要跳出本次循环继续执行下次循环,或者满足某个条件的时候,终止foreach()循环,分别会用到:continuebreak
 
$arr= array('le','yang','jun','code','life','a','b','c');
$html= '';
foreach($arr as $key => $value){
    if($value == 'a'){
      $html.= $value;
    }
    if($value =='b'){
        $html.= $value;
        continue;// 当 $value为b时,跳出本次循环
    }
    if($value =='c'){
        $html.= $value;
        break;// 当 $value为c时,终止循环
    }
    //$html.= $value;
}
echo $html; // 输出: abc

 

相关文章:

  • 2021-12-02
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
猜你喜欢
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-12-02
相关资源
相似解决方案