The array_flip()
function takes an array as its parameter, and exchanges all the keys
in that array with their values, returning the new, flipped array.
PHP array_flip() function has the following syntax.
array array_flip ( array arr )
Parameter | Is Required | Description |
---|---|---|
arr | Required. | Array to flip |
PHP array_flip() function returns the new, flipped array
<?PHP/* www .j av a 2s. c o m*/
$capitalcities['A'] = 'apple';
$capitalcities['B'] = 'better';
$capitalcities['W'] = 'java2s.com';
$flippedcities = array_flip($capitalcities);
var_dump($flippedcities);
$a2=array("d"=>"D","b"=>"B","e"=>"E","j"=>"java2s.com");
$a2 = array_flip($a2);
var_dump($a2);
?>
The code above generates the following result.