(PHP 4, PHP 5)
array_keys — 返回数组中所有的键名
array_keys() 返回 input
数组中的数字或者字符串的键名。
如果指定了可选参数 search_value
,则只返回该值的键名。否则
input
数组中的所有键名都会被返回。自
PHP 5 起,可以用 strict
参数来进行全等比较(===)。
Example #1 array_keys() 例子
<?php
$array = array(0 => 100, "color" => "red");
print_r(array_keys($array));
$array = array("blue", "red", "green", "blue", "blue");
print_r(array_keys($array, "blue"));
$array = array("color" => array("blue", "red", "green"),
"size" => array("small", "medium", "large"));
print_r(array_keys($array));
?>
以上例程会输出:
Array ( [0] => 0 [1] => color ) Array ( [0] => 0 [1] => 3 [2] => 4 ) Array ( [0] => color [1] => size )
input
An array containing keys to return.
search_value
If specified, then only keys containing these values are returned.
strict
Determines if strict comparison (===) should be used during the search.
Returns an array of all the keys in input
.
版本 | 说明 |
---|---|
5.0.0 |
Added the strict parameter.
|
Example #2 array_keys() example
<?php
$array = array(0 => 100, "color" => "red");
print_r(array_keys($array));
$array = array("blue", "red", "green", "blue", "blue");
print_r(array_keys($array, "blue"));
$array = array("color" => array("blue", "red", "green"),
"size" => array("small", "medium", "large"));
print_r(array_keys($array));
?>
以上例程会输出:
Array ( [0] => 0 [1] => color ) Array ( [0] => 0 [1] => 3 [2] => 4 ) Array ( [0] => color [1] => size )