includes()
The includes() method tests whether an array includes a certain value among its entries
Example.php
<?php use kim\present\utils\arrays\ArrayUtils;
$arrayUtils = ArrayUtils::from(["Apple", "Banana", "Carrot"]);
//Check array includes "Banana"
$arrayUtils->includes("Banana");
// expected output: true
//Check array includes "Banana" from 2
$arrayUtils->includes("Banana", 2);
// expected output: false
//Check array includes "Baccon"
$arrayUtils->includes("Baccon");
// expected output: false
$arrayUtils->includes(mixed $needle, int $start = 0) : bool;
$needle
- The value to search for.
$start
- The position in this array at which to begin searching for
valueToFind
. - Defaults to
0
.
- A
boolean
the whether the element exists in the array
ArrayUtils::includesFrom(iterable $from, mixed $needle, int $start = 0) : bool;
Last modified 5mo ago