Is there a way to stop an array_walk
from inside the anonymous function ?
Here is some sample code (that works) to show what I mean, that checks if an array has only numeric values.
$valid = true;
array_walk($parent, function ($value) use (&$valid) {
if (!is_numeric($value)) {
$valid = false;
}
});
return $valid ? 'Valid' : 'Invalid';
If I have a big enough array, and the first entry is invalid, the rest of the (redundant) checks are still done, so I would like to stop the execution.
Using break
/ continue
doesn't work (error: Fatal error: Cannot break/continue 1 level in ...
).
Note: I don't want to rewrite the code, I just want to know IF this is possible.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…