every()
The every() method tests whether all elements pass the function
<?php use kim\present\utils\arrays\ArrayUtils;
$arrayUtils = ArrayUtils::from(range(1, 30));
//Test if all elements are less than 40
$arrayUtils->every(function($num){ return $num < 40; });
// expected output: true
//Test if all elements are less than 30
$arrayUtils->every(function($num){ return $num < 40; });
// expected output: falseSyntax
$arrayUtils->every(callable $callback) : bool;Parameter
$callbackA function to test for each element, taking three arguments:
$valueThe current element being processed in the array.$keyThe index of the current element being processed in the array.$arrayThe arrayeverywas called upon.
Return value
A
booleanthe whether all elements pass the function
Prefixing
ArrayUtils::everyFrom(iterable $from, callable $callback) : bool;References
Last updated