The array_keys Function

The array_keys function retrieves the keys of an array and writes them to a new array.

Syntax

phparray_keys(array $array, mixed $search_value = null, bool $strict = false): array

Example

Let's get the keys from the array:

php<?php
  $arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5];
  
  $res = array_keys($arr);
  var_dump($res);
?>

Code execution result:

php['a', 'b', 'c', 'd', 'e']

See Also