Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

array_keys

Description

The array_keys of Array for PHP return all the keys or a subset of the keys of an array.

Syntax

array_keys(
    array $array
): array
array_keys(
    array $array,
    mixed $filter_value,
    bool $strict = false
): array

Parameters

array

An array containing keys to return.

filter_value

If specified, then only keys containing this value are returned.

strict

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

Return

Returns an array of all the keys in array.

Examples

1 · 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
)

2 · 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
)

3 · filter_value · Indexed

<?

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

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

print_r($return);

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

4 · filter_value · Associative

<?

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

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

print_r($return);

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

5 · strict · Indexed

<?

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

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

print_r($return);

?>
Array
(
    [0] => 4
)

6 · strict · Associative

<?

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

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

print_r($return);

?>
Array
(
    [0] => e
)
HomeMenu