spl - PHP lazy array mapping -
is there way of doing array_map iterator?
for example:
foreach (new mapiterator($array, $function) $value) { if ($value == $required) break; } the reason $function hard calculate , $array has many elements, need map until find specific value. array_map calculate values before can search 1 want.
i implement iterator myself, want know if there native way of doing this. couldn't find searching php documentation.
in short: no.
there no lazy iterator mapping built php. there non-lazy function iterator_apply(), nothing after.
you write 1 yourself, said. suggest extend iteratoriterator , override current() method.
Comments
Post a Comment