forEach()
The forEach() method executes a provided function once for each array element.
Example.php
<?php use kim\present\utils\arrays\ArrayUtils;
$arrayUtils = ArrayUtils::from(range(1, 10));
//Filtering values between 3 and 6
$arrayUtils->forEach(function($num){ echo $num . "~"; });
// expected output: 1~2~3~4~5~6~7~8~9~10~
$arrayUtils->forEach(callable $callback) : ArrayUtils;
$callback
A function to execute on each element, taking three arguments:$value
The current element being processed in the array.$key
The index of the current element being processed in the array.$array
The arrayevery
was called upon.
- oneself back for method chaining.
$arrayUtils->forEachAs(callable $callback) : array;
ArrayUtils::forEachFrom(iterable $from, callable $callback) : ArrayUtils;
ArrayUtils::forEachFromAs(iterable $from, callable $callback) : array;
Last modified 2yr ago