array_search
array_search
Searches the array for a given value and returns the first corresponding key if successful
**array_search** mixed $needle array $haystack bool $strict
Searches for in .
needle``haystack
needleThe searched value.
Opmerking: > If is a string, the comparison is done in a case-sensitive manner.
needle
haystackThe array.
strict
If the third parameter is set to true
then the function will search for
elements in the
. This means it will also perform a
of the
in the ,
and objects must be the same instance.
strict``array_searchidenticalhaystackstrict type comparisonneedle``haystack
Returns the key for if it is found in the
array, false otherwise.
needle
If is found in
more than once, the first matching key is returned. To return the keys for
all matching values, use with the optional
parameter instead.
needle``haystack``array_keys``filter_value
Voorbeeld: example
<?php
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array); // $key = 2;
print_r($key);
$key = array_search('red', $array); // $key = 1;
print_r($key);
?>
array_keys``array_values``array_key_exists``in_array