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

array_flip

Description

The array_flip of Array for PHP exchanges all keys with their associated values in an array.

Syntax

array_flip(
    array $array
): array

Parameters

array

An array of key/value pairs to be flipped.

Return

Returns the flipped array.

Examples

1 · indexed

<?

$array = ["a", "b", "c"];

$return = array_flip($array);

print_r($return);
Array
(
    [a] => 0
    [b] => 1
    [c] => 2
)

2 · associative

<?

$array = ["a" => 0, "b" => 1, "c" => 2];

$return = array_flip($array);

print_r($return);
Array
(
    [0] => a
    [1] => b
    [2] => c
)

3 · collision

<?

$array = ["a" => 0, "b" => 0, "c" => 2];

$return = array_flip($array);

print_r($return);
Array
(
    [0] => b
    [2] => c
)