PHP array_keys() Function Usage

The function array_keys() is used to return all the keys of an array.

Syntax:
array_keys(array, value, strict)

Parameters:
array: Required. Specifies the array from which to return the key names.
value: Optional. Specifies a certain value within the array.
strict: Optional. If this parameter is set to true, a strict type comparison will be performed.

Return value:
This function returns a new array containing all the keys in the array.

“Can you please turn down the volume?”
“Could you lower the volume, please?”

$arr = array("a" => "apple", "b" => "banana", "c" => "cherry");
$keys = array_keys($arr);
print_r($keys);

Output:

Array
(
    [0] => a
    [1] => b
    [2] => c
)

In this example, the keys of the $arr array are “a”, “b”, and “c”, so the array_keys() function is used to return a new array containing these keys.

bannerAds