PHP array_keys()Functions
Complete PHP Array Reference Manual
Examples
Returns a new array containing all the keys of the array:
<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");
print_r(array_keys($a));
?>
$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");
print_r(array_keys($a));
?>
Run Example »
Definition and Usage
The array_keys() function returns a new array containing all the keys of an array.
Syntax
array_keys(array,value,strict)
| Parameters | Description |
|---|---|
| array | Required. Specifies the array. |
| value | Optional. You can specify a value, and then only the keys corresponding to that value will be returned. |
| strict | Optional. Used together with the value parameter. Possible values:
|
Technical Details
| Return value: | Returns a new array containing all the keys of an array. |
|---|---|
| PHP Version: | 4+ |
| Changelog: | strictThe parameter was added in PHP 5.0. |
More Examples
Example 1
Using the value parameter:
<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");
print_r(array_keys($a,"Highlander"));
?>
$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");
print_r(array_keys($a,"Highlander"));
?>
Run Example »
Example 2
Using the strict parameter (false):
<?php
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",false));
?>
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",false));
?>
Run Example »
Example 3
Using the strict parameter (true):
<?php
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",true));
?>
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",true));
?>
Run Example »
Complete PHP Array Reference Manual Other Extensions