PHP - array_flip
Trieda
Metóda - array_flip
(PHP 4, PHP 5, PHP 7)
Flips key-value elements in an array, so keys will become values and values
become keys. Values must be integer or string. If the
value is e.g. an object, PHP throws a warning and the key is not used. In the
case of more identical keys, the last element will be used and the previous ones
will be discarded.
Procedurálne
- function array_flip (array $array) : array
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $array | array | An array to be flipped. |
Mávratovej hodnoty
Vracia: array
The flipped array or NULL on failure.
Príklady
<?php
$array = [1 => 'a', 2 => 'b', 3 => 'a'];
$array = array_flip($array);
print_r($array);
Súvisiace manuály
- function array_keys (array $array, mixed $search_value = null, bool $strict = false) : array
- function array_reverse (array $array, bool $preserve_keys = false) : array
- function array_values (array $array) : array
