array_keys in PHP

Syntax of array_keys

array array_keys(array array[, mixed value[, bool strict]])

Returns an array containing all of the keys in the given array. If the second parameter is provided, only keys whose values match value are returned in the array. If strict is specified and is true, a matched element is returned only when it is of the same type and value as value

Example of array_keys

<?php
$array = array(0 => 100, "color" => "red");
print_r(array_keys($array));

$array = array("blue", "red", "green", "blue", "blue");
print_r(array_keys($array, "blue"));

$array = array("color" => array("blue", "red", "green"),
               "size"  => array("small", "medium", "large"));
print_r(array_keys($array));
?>
Array
(
    [0] => 0
    [1] => color
)
Array
(
    [0] => 0
    [1] => 3
    [2] => 4
)
Array
(
    [0] => color
    [1] => size
)

Leave a Comment