Home Menu

array_keys

Return all the keys or a subset of the keys of an array

Syntax

array_keys ( array $array ) : array
array_keys ( array $array , mixed $search_value [, bool $strict = FALSE ] ) : array

Parameters

array

An array containing keys to return.

search_value

If specified, then only keys containing these values are returned.

strict

Determines if strict comparison (===) should be used during the search.

Return

Returns an array of all the keys in array.

Examples

array | Indexed

<?

$array = array(null, false, true, 0, 1);

$return = array_keys($array);

print_r($return);

?>
Array
(
    [0] => 0
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 4
)

array | Associative

<?

$array = array(
    "a" => null,
    "b" => false,
    "c" => true,
    "d" => 0,
    "e" => 1
);

$return = array_keys($array);

print_r($return);

?>
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
    [4] => e
)

search_value | Indexed

<?

$array = array(null, false, true, 0, 1);
$search_value = 1;

$return = array_keys($array, $search_value);

print_r($return);

?>
Array
(
    [0] => 2
    [1] => 4
)

search_value | Associative

<?

$array = array(
    "a" => null,
    "b" => false,
    "c" => true,
    "d" => 0,
    "e" => 1
);
$search_value = 1;

$return = array_keys($array, $search_value);

print_r($return);

?>
Array
(
    [0] => c
    [1] => e
)

strict | Indexed

<?

$array = array(null, false, true, 0, 1);
$search_value = 1;
$strict = true;

$return = array_keys($array, $search_value, $strict);

print_r($return);

?>
Array
(
    [0] => 4
)

strict | Associative

<?

$array = array(
    "a" => null,
    "b" => false,
    "c" => true,
    "d" => 0,
    "e" => 1
);
$search_value = 1;
$strict = true;

$return = array_keys($array, $search_value, $strict);

print_r($return);

?>
Array
(
    [0] => e
)

PHP

JesusBible
HTMLCSSJSPHPSVGMore
AboutTerms