Exchange values with keys
suggest changearray_flip() returns a new array with keys and values swapped. It does not change $colors. Values must be strings or integers. If two values are the same, the later one overwrites the earlier one.
$colors = array(
'one' => 'red',
'two' => 'blue',
'three' => 'yellow',
);
$flipped = array_flip($colors); // $flipped is the following array:
/* array(
'red' => 'one',
'blue' => 'two',
'yellow' => 'three'
); */
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents