Example
Returns a new array containing all the key names in the array :
<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");
print_r(array_keys($a));
?> Copy after login
Definition and usage
array_keys() function returns the value containing A new array of all keys in the array.
Syntax
array_keys(array,value,strict) Copy after login
Parameters Description 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 - Default value. Independent of type, the number 5 is the same as the string "5".
Technical details
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. 更多实例
实例 1
使用 value 参数:
<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");
print_r(array_keys($a,"Highlander"));
?> Copy after login
实例 2
使用 strict 参数 (false):
<?php
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",false));
?> Copy after login
实例 3
使用 strict 参数 (true):
<?php
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",true));
?> Copy after login
The above is the detailed content of PHP function array_keys() returns a new array containing all the key names in the array. For more information, please follow other related articles on the PHP Chinese website!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
2023-03-15 16:54:01
2023-03-15 12:26:02
2023-03-14 18:58:01
2023-03-14 11:30:01
1970-01-01 08:00:00
2023-03-16 15:20:01
1970-01-01 08:00:00
1970-01-01 08:00:00
1970-01-01 08:00:00
1970-01-01 08:00:00