Array_keys () Definition and usage
The Array_keys () function returns a new array that contains all the key names in the array.
If the second argument is supplied, only the key name of the value is returned.
If the strict parameter is specified as true, PHP uses the congruent comparison (= = =) to strictly check the data type of the key value.
Grammar
Array_keys (Array,value)
Parameter description
Array 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-Returns the key name with the specified value, based on the type.
False-The default value. Does not depend on the type.
Example 1
Copy the Code code as follows:
$a =array ("a" = "Horse", "b" = "Cat", "C" and "Dog");
Print_r (Array_keys ($a));
?>
Output:
Array ([0] = a [1] = b [2] = = c)
Example 2
Use the value parameter:
Copy the Code code as follows:
$a =array ("a" = "Horse", "b" = "Cat", "C" and "Dog");
Print_r (Array_keys ($a, "Dog"));
?>
Output:
Array ([0] + = c)
Example 3
Use the strict parameter (false):
Copy the Code code as follows:
$a =array (10,20,30, "10");
Print_r (Array_keys ($a, "ten", false));
?>
Output:
Array ([0] = 0 [1] = 3)
Example 4
Use the strict parameter (true):
Copy the Code code as follows:
$a =array (10,20,30, "10");
Print_r (Array_keys ($a, "ten", true));
?>
Output:
Array ([0] = 3)
The above describes the ArrayList namespace php array function sequence Array_keys-get the array key name, including the ArrayList namespace aspects of the content, I hope to be interested in PHP tutorial friends helpful.