Map occurrences
Mapping works a bit like a combination of all()
and forEach()
. It returns all matched elements, after
they have been iterated (and potentially altered) using map()
callback (which accepts Detail
details).
#
Map matched occurrencesSo instead of returning all elements:
...you can map them - to any other value, by callback:
#
Variable callbacksYou can invoke map()
with any valid PHP callable
which accepts one
string parameter (or no parameters) - just like first()
.
#
Arbitrary return typesAgain, just like first()
, this method can return values of any type, including: objects, arrays,
booleans and null
.
flatMap()
#
You can just as easily create a flattened map.
Read more about flatMap()
on the next page.