PHP array_keys function

Last Updated: February 13, 2022

array_keys — Get all keys of the array or subset of the keys

Syntax

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

Supports (PHP 4, PHP 5, PHP 7, PHP 8)

Parameters

array – the array you want to evaluate

Return Value

The last key of the array

Example

<?php

$array = array(0 => 100, "color" => "red");
print_r(array_keys($array));

$array = array("blue", "red", "green", "blue", "blue");
print_r(array_keys($array, "blue"));
?>

Output

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