Monday, 26 August 2013

PHP Function array_search()

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.

Paramters

ParameterDescription
valueRequired. Specifies a value to be searched.
arrayRequired. Specifies an array.
strictOptional. 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 following result:
b

No comments:

Post a Comment