Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP array_keys() Function

PHP array_keys() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Return a new array containing all the keys of an array:

"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 only the keys corresponding to that value will be returned.
strict Optional. Used together with the value parameter. Possible values:
  • true - Returns 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 the array.
    PHP Version: 4+
    Changelog: strict This parameter was added in PHP 5.0.

    More examples

    Example 1

    Using the value parameter:

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

    Run Example »

    Example 2

    Using the strict parameter (false):

    Run Example »

    Example 3

    Using the strict parameter (true):

    Run Example »


    PHP Array ReferenceComplete PHP Array Reference Manual