PHP array_keys() function

PHP array_key_exists() function
PHP array_map() function

The array_keys function simply extracts the keys from the given array and returns them. The result of this function is an array containing the keys from the input array.

What is the syntax of the array_keys function in PHP?

array_keys(array, value, strict)
ParameterDescription
arrayThe array from which keys are to be extracted – Required
valueThe values whose keys are to be extracted – Optional
strictSpecify the type strictness of the value therefore, can be either true or false.
When set to true: the value parameter “5” and 5 will not be considered to be the same.
When set to false: the value parameter “5” and 5 will be considered to be the same.
array_keys function in PHP

Examples of array_keys function

<?php
$array = array("Honda"=>"cd70","Suzuki"=>"125","Kawasaki"=>"150");
print_r(array_keys($array));
?>

In the above example, the output will be an array containing the keys from the given array.

<?php
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",false));
?>

In the above example, the strict parameter is set to false.

<?php
$a=array(10,20,30,"10");
print_r(array_keys($a,"10",true));
?>

In the above example, the strict parameter is set to true.

PHP array_key_exists() function
PHP array_map() function

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top