array_keys

array array_keys(array array) 

Returns all valid keys for the given array.

Returns:

Indexed array of keys; NULL on failure

Description:

Retrieves all the keys from an array and returns them as an indexed array.

Version:

PHP 4

Existing since version 4.0

Example:

Get the keys from arrays
$hash1 = array("lions", "tigers", "bears", "oh my"); 
$hash2 = array("r" => "red", "g" => "green", "b" => "blue"); 
echo "Keys for \$hash1: ", implode(", ", array_keys($hash1)), "\n"; 
echo "Keys for \$hash2: ", implode(", ", array_keys($hash2)); 

Output: 
Keys for $hash1: 0, 1, 2, 3 
Keys for $hash2: r, g, b 

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.