Searches an array for an element.
The function array_search() searches an array for an element. If it is found, the index or key is returned. Otherwise, it returns FALSE. If more than one element matches, the first is returned.
<?php
$array1 = array("one", "two", "three");
$array2 = array(
"un" => "one",
"deux" => "two",
"trois" => "three");
print "Print index of \"two\": " . array_search("two", $array1, TRUE) . "<br>";
print "Two in French is: " . array_search("two", $array2, TRUE);
?>
Print index of "two": 1
Two in French is: deux
The code shows array_search() in use on an index and an associative array.