find()
The find() method find the value of the first element that pass function.
Example.php
<?php use kim\present\utils\arrays\ArrayUtils;
$arrayUtils = ArrayUtils::from(["Apple", "Banana", "Carrot", "Bacon"]);
//Find values starting with B
$arrayUtils->find(function($name){ return $name[0] === "B"; });
// expected output: "Banana"
$arrayUtils->find(callable $callback) : mixed;
$callback
A function to execute on each value in the array, taking 3 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.
- The value of the first element in the array that pass function. Otherwise,
NULL
is returned.
ArrayUtils::findFrom(iterable $from, callable $callback) : mixed;
Last modified 2yr ago