October 2005
Intermediate to advanced
372 pages
11h 35m
English
array_flip()
array array_flip ( array arr )The array_flip() function takes an array as its parameter, and exchanges all the keys in that array with their matching values, returning the new, flipped array. You can see how it works in this script:
$capitalcities['England'] = 'London';
$capitalcities['Scotland'] = 'Edinburgh';
$capitalcities['Wales'] = 'Cardiff';
$flippedcities = array_flip($capitalcities);
var_dump($flippedcities);The output is this:
array(3) {
["London"]=>
string(7) "England"
["Edinburgh"]=>
string(8) "Scotland"
["Cardiff"]=>
string(5) "Wales"
}As you can see, London, Edinburgh, and Cardiff are the keys in the array now, with England, Scotland, and Wales as the values.