Array_keys () Definition and usage
The Array_keys () function returns a new array containing all the key names in the array.
If the second argument is provided, only the key name with the value is returned.
If the strict parameter is specified as true, PHP uses strict equality comparisons (= = =) to strictly check the data type of the key value.
Grammar
Array_keys (Array,value)
Parameter description
Array required. A specified array of inputs.
Value is optional. The index (key) of the specified value.
Strict optional. Used with the value parameter. Possible values:
True-Returns the key name with the specified value, based on the type.
False-default value. Not dependent on type.
Example 1
Copy Code code as follows:
<?php
$a =array ("a" => "horse", "B" => "Cat", "C" => "Dog");
Print_r (Array_keys ($a));
?>
Output:
Array ([0] => a [1] => b [2] => c)
Example 2
Use the value parameter:
Copy Code code 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 Code code as follows:
<?php
$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 Code code as follows:
<?php
$a =array (10,20,30, "10");
Print_r (Array_keys ($a, "ten", true));
?>
Output:
Array ([0] => 3)