Anonymous user / Log In Register
Wallet: 3.00
Daily Credits:
1.20 / 1.20

PHP Functions Online


(PHP 4 >= 4.0.5, PHP 5)

array_searchSearches the array for a given value and returns the corresponding key if successful

mixed array_search(mixed $needle , array $haystack[, bool $strict = false])

Checkout ? #

Item Description Item Price Your Price

Preview #

${{ }} = {{ variable.param|getValue:variable.form:true }};
{{ call.result}} = ;

Description #

mixed array_search ( mixed $needle , array $haystack [, bool $strict = false ] )

Searches haystack for needle.

Parameters #


The searched value.


If needle is a string, the comparison is done in a case-sensitive manner.


The array.


If the third parameter strict is set to TRUE then the array_search() function will search for identical elements in the haystack. This means it will also check the types of the needle in the haystack, and objects must be the same instance.

Return Values #

Returns the key for needle if it is found in the array, FALSE otherwise.

Examples #

Example #1 array_search() example

= array(=> 'blue'=> 'red'=> 'green'=> 'red');

$key array_search('green'$array); // $key = 2;
$key array_search('red'$array);   // $key = 1;

Changelog #

Version Description
5.3.0 As with all internal PHP functions as of 5.3.0, array_search() returns NULL if invalid parameters are passed to it.
4.2.0 Prior to PHP 4.2.0, array_search() returns NULL on failure instead of FALSE.

See Also #