Array Keys Function in PHP

In this article I explain array keys function in PHP.
  • 1685

PHP array_keys Function

The PHP array_keys function accepts an array and returns a new array that contains only its keys.

Syntax

array_keys(array,values)

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

array-keys-function-in-php.jpg

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.