Home  >  Article  >  Backend Development  >  PHP function array_keys() returns a new array containing all the key names in the array

PHP function array_keys() returns a new array containing all the key names in the array

黄舟
黄舟Original
2017-11-08 09:22:451848browse

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));
?>

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)
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

The strict parameter is

更多实例

实例 1

使用 value 参数:

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

实例 2

使用 strict 参数 (false):

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

实例 3

使用 strict 参数 (true):

<?php
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",true));
?>
Return value: Returns a new array containing all keys in the array.
PHP Version: 4+
##Update Log : new in PHP 5.0.

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:
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