array_search() — php array function to search the key of the item in an array

The php array_search function search the given item in an array and returns its corresponding index.It is a good way to check to see if a value exists in an array. Remember that all arrays have a default index of 0, so the first element has a key of 0 when key labels are not specified in the array.
Syntax:

    array_search(value,array,strict)

In the above syntax “value” specifies the value to be searched for, “array” specifies the array in which to search, “strict” specifies a strict comparison (===).

Example:

    <?php
    $b=array("c"=>"Cherry","b"=>"Strawberry");
    $a=array("a"=>"5","b"=>5,"c"=>"5");
    print_r(array_search("Cherry",$b));
    print_r(array_search(5,$a,true);
    ?>

Result:

    c
    b

In the above example the array “$b”, is searched for and displays the value “cherry”, for the array “$a” a strict comparison is done and the result is displayed as “b”,since 5 and “5” are not equal when (===) is used.