php 怎么根据循环结果判断是否进行下一次循环? 10
publicfunctiona(){$arr=[['id'=>1,'name'=>'aaa'],['id'=>2,'name'=>'bbb'],['id'=>3,'nam...
public function a(){
$arr = [['id'=>1,'name'=>'aaa'],['id'=>2,'name'=>'bbb'],['id'=>3,'name'=>'ccc']];
foreach ($arr as $key=>$val){
$result = $this->b($val['id'],$val['name']);
//判断第一次执行结果进行下一次
}
}
public function b($id,$name){
//其他逻辑
return ['code'=>1,'msg'=>'成功'];
} 展开
$arr = [['id'=>1,'name'=>'aaa'],['id'=>2,'name'=>'bbb'],['id'=>3,'name'=>'ccc']];
foreach ($arr as $key=>$val){
$result = $this->b($val['id'],$val['name']);
//判断第一次执行结果进行下一次
}
}
public function b($id,$name){
//其他逻辑
return ['code'=>1,'msg'=>'成功'];
} 展开
1个回答
展开全部
public function a(){
$arr = [['id'=>1,'name'=>'aaa'],['id'=>2,'name'=>'bbb'],['id'=>3,'name'=>'ccc']];
foreach ($arr as $key=>$val){
$result = $this->b($val['id'],$val['name']);
if($result['code']!='1') return;//失败调出循环,成功继续循环下一次
}
}
$arr = [['id'=>1,'name'=>'aaa'],['id'=>2,'name'=>'bbb'],['id'=>3,'name'=>'ccc']];
foreach ($arr as $key=>$val){
$result = $this->b($val['id'],$val['name']);
if($result['code']!='1') return;//失败调出循环,成功继续循环下一次
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询