Array_values () Definition and usage
The array_keys () function returns a new array containing all the key names in the array.
If the second parameter is provided, only the key name of the value is returned.
If the strict parameter is set to true, PHP will use full comparison (=) to strictly check the data type of the key value.
Syntax
Array_keys (array, value)
Parameter description
Array is required. Specifies the input array.
Value is optional. The index (key) of the specified value ).
Strict is optional. Used with the value parameter. Possible values:
True-return the key name with the specified value based on the type.
False-default value. Does not depend on type.
Example 1
Copy codeThe Code is as follows:
<? Php
$ A = array ("a" => "Horse", "B" => "Cat", "c" => "Dog ");
Print_r (array_keys ($ ));
?>
Output:
Array ([0] => a [1] => B [2] => c)
Example 2
Use the value parameter:
Copy codeThe Code is as follows:
<? Php
$ A = array ("a" => "Horse", "B" => "Cat", "c" => "Dog ");
Print_r (array_keys ($ a, "Dog "));
?>
Output:
Array ([0] => c)
Example 3
Use the strict parameter (false ):
Copy codeThe Code is as follows:
<? Php
$ A = array (10, 20, 30, "10 ");
Print_r (array_keys ($ a, "10", false ));
?>
Output:
Array ([0] => 0 [1] => 3)
Example 4
Use the strict parameter (true ):
Copy codeThe Code is as follows:
<? Php
$ A = array (10, 20, 30, "10 ");
Print_r (array_keys ($ a, "10", true ));
?>
Output:
Array ([0] => 3)