The array_keys function simply extracts the keys from the given array and returns them. The result of this function is an array containing the keys from the input array.
What is the syntax of the array_keys function in PHP?
array_keys(array, value, strict)
Parameter | Description |
---|---|
array | The array from which keys are to be extracted – Required |
value | The values whose keys are to be extracted – Optional |
strict | Specify the type strictness of the value therefore, can be either true or false. When set to true: the value parameter “5” and 5 will not be considered to be the same. When set to false: the value parameter “5” and 5 will be considered to be the same. |
Examples of array_keys function
<?php
$array = array("Honda"=>"cd70","Suzuki"=>"125","Kawasaki"=>"150");
print_r(array_keys($array));
?>
In the above example, the output will be an array containing the keys from the given array.
<?php
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",false));
?>
In the above example, the strict parameter is set to false.
<?php
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",true));
?>
In the above example, the strict parameter is set to true.