Skip to content

array_search ​

php
mixed array_search(mixed $igla, array $tablica)

Returns the index of an element if $igla is found in $tablica, or false if it is not found. Comparison is strict.

Example:

php
$tablica = array(2, 4, 6);
$x = 2;
$indeks = array_search($x, $tablica);
if ($indeks === false) {
print("Number ".$x." is not in the set");
} else {
print("Number ".$x." is element ".($indeks+1)." of the set");
}

Result:

Number 2 is element 1 of the set