1 回答
TA贡献1946条经验 获得超4个赞
您能否让 myFunction 返回一个值来指示循环是否应该停止?
foreach($user_data as $data_chunks){
foreach($data_chunks as $data_set){
foreach($data_set as $data){
// V-- Collect return value below
$returned_stop = myFunction($data, function($returned_data, $stop){
if($stop){
//log error
}
print $returned_data." ";
});
if ($returned_stop) { // <- Check to stop here
break 2;
}
}
}
}
function myFunction($data, callable $f){
$stop = false;
if($data>5){
$stop = true;
}
$data_to_return = $data*2;
$f($data_to_return,$stop);
return($stop); // <- Return here
}
- 1 回答
- 0 关注
- 159 浏览
添加回答
举报