Latest web development tutorials

PHP array_keys () function

PHP Array Reference Complete PHP Array Reference

Examples

It returns an array containing a new array of all the key names:

<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");
print_r(array_keys($a));
?>

Running instance »

Definition and Usage

array_keys () function returns an array containing a new array of all the keys.


grammar

array_keys( array,value,strict )

参数 描述
array 必需。规定数组。
value 可选。您可以指定键值,然后只有该键值对应的键名会被返回。
strict 可选。与 value 参数一起使用。可能的值:
  • true - 返回带有指定键值的键名。依赖类型,数字 5 与字符串 "5" 是不同的。
  • false - 默认值。不依赖类型,数字 5 与字符串 "5" 是相同的。

technical details

return value: Returns a new array array containing all the keys.
PHP version: 4+
Update log: strict parameter is new in PHP 5.0 in.


More examples

Example 1

Use the value parameter:

<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");
print_r(array_keys($a,"Highlander"));
?>

Running instance »

Example 2

Use strict parameter (false):

<?php
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",false));
?>

Running instance »

Example 3

Use strict parameter (true):

<?php
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",true));
?>

Running instance »


PHP Array Reference Complete PHP Array Reference