PHP » Arrays » array_keys()

Syntax:
array array_keys(array array [, mixed search])
array
The array with keys to be found.
search
Value to search for.

Returns the keys of an array.

The array_keys() function returns an array with all the keys of another array. If the input array is not an associative array, the key array will contain the indexes. If the search parameter is used, only the keys of the elements equal to the search parameter will be returned.

Examples

Code:
<?php

$array1 = array(
   "strawberry" => "red",
   "blueberry" => "blue",
   "raspberry" => "red");

// find red berries
foreach (array_keys($array1, "red") as $berry)
   print "$berry ";

?>
Output:
strawberry raspberry
Explanation:

This example shows how array_keys can be used with the search parameter.

See Also: