indexOf()
The indexOf() method get first index at which a given element can be found in the array
<?php use kim\present\utils\arrays\ArrayUtils;
$arrayUtils = ArrayUtils::from(["Apple", "Banana", "Carrot"]);
//Check array includes "Banana"
$arrayUtils->indexOf("Banana");
// expected output: 1
//Check array includes "Carrot" from 2
$arrayUtils->indexOf("Banana");
// expected output: null
//Check array includes "Baccon"
$arrayUtils->indexOf("Baccon");
// expected output: nullSyntax
$arrayUtils->indexOf(mixed $needle, int $start = 0) : int|string|null;Parameter
$needleThe value to search for.
$startThe position in this array at which to begin searching for
valueToFind.Defaults to
0.
Return value
The first index of the element in the array. If not founded, returns
NULL.
Prefixing
ArrayUtils::indexOfFrom(iterable $from, mixed $needle, int $start = 0) : int|string|null;References
Last updated