indexOf()
The indexOf() method get first index at which a given element can be found in the array
Example.php
<?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: null
$arrayUtils->indexOf(mixed $needle, int $start = 0) : int|string|null;
$needle
- The value to search for.
$start
- The position in this array at which to begin searching for
valueToFind
. - Defaults to
0
.
- The first index of the element in the array. If not founded, returns
NULL
.
ArrayUtils::indexOfFrom(iterable $from, mixed $needle, int $start = 0) : int|string|null;
Last modified 2yr ago