Map with keys (Flat map)
There are cases when you would like to create a single list of all your matches.
flatMap() is great for it.
In other words, it allows you to return one, zero or more elements from your mapping function.
#Making a flat map
flatMap() is basically method
map(), from which you can return multiple values.
flatMap() only accepts an
array as its return type. Returning a single element and implicitly creating a one-element
array under the hood would be counter-intuitive and error-prone.
flatMap() accepts only
array as its return type.
You can invoke
flatMap() with any valid PHP
callable, which accepts one or zero string parameters and returns
callable passed to
flatMap() must return an array.
InvalidReturnValueException is thrown, otherwise.
#Mapping with keys
toMap() can be used to return a dictionary, based on matched occurrences.
Detail.offset() returns offset as a valid UTF-8 sequence, whereas
counts them as bytes. To return bytes number with T-Regx as well,
Duplicate keys are not allowed in PHP arrays, so they'll only appear once in the results.