every()
The every() method tests whether all elements pass the function
Example.php
<?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: false
$arrayUtils->every(callable $callback) : bool;
$callback
A function to test for 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.
- A
boolean
the whether all elements pass the function
ArrayUtils::everyFrom(iterable $from, callable $callback) : bool;
Last modified 2yr ago