array_keys()

array_keys() — Return all the keys or a subset of the keys of an array.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

array_keys(array $array): array array_keys(array $array, mixed $filter_value, bool $strict = false): array

Parameters

ParameterTypeWhat it takes
$arrayarrayAn array containing keys to return.
$filter_valuemixedIf specified, then only keys containing this value are returned.
$strictboolDetermines if strict comparison (===) should be used during the search.

Return value

Returns an array of all the keys in array.

Example

A runnable snippet:

$array = array(0 => 100, "color" => "red"); print_r(array_keys($array)); $array = array("blue", "red", "green", "blue", "blue"); print_r(array_keys($array, "blue")); $array = array("color" => array("blue", "red", "green"), "size" => array("small", "medium", "large")); print_r(array_keys($array));

Output:

Array ( [0] => 0 [1] => color ) Array ( [0] => 0 [1] => 3 [2] => 4 ) Array ( [0] => color [1] => size )

See also

array_values(), array_combine(), array_key_exists(), array_search()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page array_keys() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.