The array_search () function is the same as the in_array () function. You can find a key value in the array. If this value is found, the key name of the matching element is returned. If not found, false is returned.
If the third parameter strict is set to true, the key name of the corresponding element is returned only when the data type and value are consistent.
Array_search (value, array, strict)
Instance
The code is as follows: |
Copy code |
<? Php Tutorial $ A = array ("a" => "5", "B" => 5, "c" => "5 "); Echo array_search (5, $ a, true ); ?> Output: |
B
Further, use it to delete array elements
The code is as follows: |
Copy code |
$ Arr = Array ([0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day .); If ($ key = array_search ('day', $ arr ))){ Unset ($ arr [$ key]); } |
Delete them and use other values instead.
The code is as follows: |
Copy code |
If ($ key = array_search ('day', $ arr ))){ Array_splice ($ arr, $ key, 1 ); } |