|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-03-24 08:53 UTC] 6562680 at gmail dot com
Description:
------------
Am using array_walk/*_recursive to work with reports (seems like):
```
[
'created' => [],
'updated' => [],
// * => []
]
```
When we have large amount of records we should run 10000 callbacks even if statement
```
static $break = false;
if ($break) return null;
$break = true;
```
was declared
The solution could be
```
class BreakException extends \Exception {}
try {
array_walk_recursive($array, function () {
throw new BreakException();
});
} catch (Exception $e) {
}
```
Would be great to implement some statement like foreach `break` to avoid building stack trace while using that feature (because of foreach supports only single level traversing)
Thank you.
Test script:
---------------
-
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 21:00:01 2025 UTC |
If few minutes was found solution like that: ``` <?php $arr = [ 0 => [1,2,3], 1 => [4,5,6], ]; $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($arr)); var_dump($iterator); foreach($iterator as $key => $value) { echo "$key => $value\n"; break; } ``` I think solved if seems nice.