PHP array_keys() 函数
实例
返回包含数组中所有键名的一个新数组:
<?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 key names of the array.
If the second parameter is provided, only the key names with the specified key value will be returned.
If strict If the parameter is specified as true, PHP will use strict comparison (===) to strictly check the data type of the key value.
Syntax
array_keys(array,value,strict)
Parameters | Description |
---|---|
array | Required. Specifies the array. |
value | Optional. You can specify a key value, and only the key names corresponding to that key value will be returned. |
strict |
Optional. With value Parameters used together. Possible values:
|
Technical Details
Return Value: | Returns a new array containing all the keys of the array. |
PHP Version: | 4+ |
Update Log: | strict The parameter was added in PHP 5.0. |
More Examples
Example 1
Use value parameter:
<?php $a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander"); print_r(array_keys($a,"Highlander")); ?>
Example 2
Use strict parameter (false):
<?php $a=array(10,20,30,"10"); print_r(array_keys($a,"10",false)); ?>
Example 3
Use strict parameter (true):
<?php $a=array(10,20,30,"10"); print_r(array_keys($a,"10",true)); ?>