Return a new array containing all keys in the array:
<?php$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");print_r(array_keys($a));?>The array_keys() function returns a new array containing all the keys in the array.
array_keys( array,value,strict )
| parameter | describe |
|---|---|
| array | Required. Specifies an array. |
| value | Optional. You can specify a key value, and then only the key name corresponding to that key value will be returned. |
| strict | Optional. Used with the value parameter. Possible values: true - Returns the key name with the specified key value. Depending on the type, the number 5 is different from the string "5". false - the default value. Independent of type, the number 5 is the same as the string "5". |
| Return value: | Returns a new array containing all keys in the array. |
|---|---|
| PHP version: | 4+ |
| Update log: | The strict parameter is new in PHP 5.0. |
Use the value parameter:
<?php$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");print_r(array_keys($a,"Highlander"));? >Use strict parameter (false):
<?php$a=array(10,20,30,"10");print_r(array_keys($a,"10",false));?>Use strict parameter (true):
<?php$a=array(10,20,30,"10");print_r(array_keys($a,"10",true));?>