The following small series will bring you an article on the PHP search for the given simple instance array_search function in the array. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at it with Xiaobian.
Array_search ()
The PHP array_search () function is used to search for a given value in the array. if the value is successful, the corresponding key name is returned. otherwise, FALSE is returned.
Syntax:
Mixed array_search (mixed needle, array [, bool strict]) parameter description:
| Parameters |
Description |
| Needle |
The value to be searched in the array. if it is a string, it is case sensitive. |
| Array |
Array to be retrieved |
| Strict |
Optional. If this parameter is set to TRUE, the needle and array value types are checked. |
Because the starting index number of the index array may be 0, this function may return non-Boolean values equivalent to FALSE, such as 0 or "", therefore, you must use the = operator to strictly verify the value returned by the function.
Example:
<? Php $ arr_a = array (0 => "a", 1 => "B", 2 => "c"); $ key = array_search ("", $ arr_a); if ($ key! = FALSE) {echo "key name: $ key";} else {echo 'no matching result';}?>
The output result is as follows:
Key name: 0 if needle appears more than once in array, the first matched Key is returned. To return keys of all matched values, use the array_keys () function.
The above PHP search for the given simple instance array_search function in the array is all the content shared by the small editor. I hope you can give us a reference and support for me.