PHP array_keys() Function

PHP array_keys Function


Definition:

The array_keys() function return all the keys or a subset of the keys of an array.

Syntax :

The basic syntax of the array_keys() function is given with:

  array_keys(arrayvaluestrict);

Parameters :

The array_keys() function accepts the following parameters.

Parameter Description
array Required. Specifies the array to be used.
value Optional. If specified, then only keys containing these values are returned.
strict Optional. Determines if strict comparison (===) should be used during the value search. Possible values are true and false. Default value is false.

Example1 : The following example shows the array_keys() function in action.

 Output :

Array
(
    [0] => Web
    [1] => Designing
    [2] => House
    [3] => online
)

Example2: 

The following example return all the keys from the persons array containing the value 32.

Output :

Array
(
    [0] => Clark
    [1] => Peter
)

Example3 : The following example will return only those key which has integer value 32 using strict comparison. This can be simply done by setting the strict parameter to true.

Output :

Array
(
    [0] => Peter
)