PHP array_flip()Function
Complete PHP Array Reference Manual
Examples
Reverse the keys and their associated values in an array:
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$result=array_flip($a1);
print_r($result);
?>
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$result=array_flip($a1);
print_r($result);
?>
Run Example »
Definition and Usage
The array_flip() function is used to reverse/exchange the keys and their associated values in an array.
Syntax
array_flip(array);
| Parameter | Description |
|---|---|
| array | Required. Specifies the array whose key/value pairs are to be flipped. |
Technical Details
| Return Value: | If the flip is successful, the flipped array is returned. If the flip fails, NULL is returned. |
|---|---|
| PHP Version: | 4+ |
Complete PHP Array Reference Manual Other Extensions