Array Keys Function in PHP
In this article I explain array keys function in PHP.
PHP array_keys Function
The PHP array_keys function accepts an array and returns a new array that contains only its keys.
Syntax
Parameters
The parameters of the array_keys function are:
Parameter |
Description |
array |
It specifies an array. |
values |
It specifies values, then only keys with this values are returned. |
Example
An example of the array_keys function is:
<?php
echo "<pre>";
$val = array("a" => "Apple", "b" => "Mango", "c" => "Orange", "Banana");
echo "Without Value Parameter: ";
print_r(array_keys($val));
echo "<pre>";
echo "With Value Parameter: ";
print_r (array_keys($val,"Mango"));
?>
Output