array_search function in php
0 2260
The array_search() function is an inbuilt of PHP which used to search a particular value in an array and return the key. This function return FALSE if the value is not found in the array.
If the value occurs multiple times then it returns the key of value which match first.
array_search function syntax:
array_search(value, array, strict_parameter_value);
Here:
- Value indicates the item which we want to search in the array. It is mandatory.
- Array is the array in which we want to search item. It is also mandatory.
- strict_parameter_value is set the strictness of search. It has two value either TRUE or FALSE. Default value of this parameter is FALSE. It is not mandatory.
array_search function example:
<?php // This example define the use of array_search() function $arr=array("coding", "tag", "is", "a", "Prominent", "Portal", "to learn", "latest technologies"); $value="Prominent"; $result=array_search($value,$arr); echo 'The key of '.$value.' is '.$result; ?>
Output:
Share:
Comments
Waiting for your comments