Mar 21

Array Search

array_search : Searches the array for a given value and returns the corresponding key if successful.

array_search ( $value ,  $array [, bool $strict = false ] )

Strict : if strict set to true then array_search() function search for identical element. Means it check type of value in the array and object must be same.


$array = array(0 => ‘blue’, 1 => ‘red’, 2 => ‘green’, 3 => ‘red’);

$key = array_search(‘green’, $array);
echo $key;

Output : 2

$key = array_search(‘red’, $array);
echo $key

Output : 1

for More Refernce

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>