PHP - Function array_search()


Advertisements


Syntax

array_search($value, $array [,$strict]);

Definition and Usage

The array_search() function search an array for a value and returns the key.

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

Parameters

Parameter Description
value Required. Specifies a value to be searched.
array Required. Specifies an array.
strict Optional. If it is set to TRUE then the array_search() will also check the types of the search in the array.

Return Values

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

Example

Try out following example −

<?php
   $array=array("a"=>"banana","b"=>"apple","c"=>"orange");
   
   print_r(array_search("apple", $array));
?> 

This will produce the following result −

b

php_function_reference.htm

Advertisements