The array_keys() function returns an array containing the keys of a given array.
| <?php $a=array(“Volvo”=>“XC90”,“BMW”=>“X5”,“Toyota”=>“Highlander”); print_r(array_keys($a)); ?> |
The array_keys() function returns an array of the keys.
| array_keys(array, value, strict) |
|
Parameter |
Description |
|
array |
Required. Specifies the array. |
|
value |
Optional. If a value is specified, only the keys corresponding to that value are returned. |
|
strict |
Optional. Used with the value parameter. Possible values:
|
|
Return Value: |
Returns an array of the keys. |
|
PHP Version: |
4+ |
|
Changelog: |
The strict parameter was introduced in PHP 5.0. |
When using the value parameter:
| <?php $a=array(“Volvo”=>“XC90”,“BMW”=>“X5”,“Toyota”=>“Highlander”); print_r(array_keys($a,“Highlander”)); ?> |
When using the strict parameter set to false:
| <?php $a=array(10,20,30,“10”); print_r(array_keys($a,“10”,false)); ?> |
When using the strict parameter set to true:
| <?php $a=array(10,20,30,“10”); print_r(array_keys($a,“10”,true)); ?> |