PHP array_keys()Functions

PHP Array ReferenceComplete PHP Array Reference Manual

Examples

Returns a new array containing all the keys of the array:

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

Run Example »

Definition and Usage

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


Syntax

array_keys(array,value,strict)

Parameters Description
array Required. Specifies the array.
value Optional. You can specify a value, and then only the keys corresponding to that value will be returned.
strict Optional. Used together with the value parameter. Possible values:
  • true - Returns the keys with the specified value. Type-dependent, the number 5 and the string "5" are different.
  • false - Default. Not type-dependent, the number 5 and the string "5" are the same.

Technical Details

Return value: Returns a new array containing all the keys of an array.
PHP Version: 4+
Changelog: strictThe parameter was added in PHP 5.0.


More Examples

Example 1

Using the value parameter:

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

Run Example »

Example 2

Using the strict parameter (false):

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

Run Example »

Example 3

Using the strict parameter (true):

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

Run Example »


PHP Array ReferenceComplete PHP Array Reference Manual Other Extensions