Exchange values with keys

suggest change

array_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'
); */

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents