array_flip- exchanging keys and values in an array
array array_flip ( array $trans )
Array_flip () returns a reversed array, such as trans the key name in the value, and the trans value in the key name.
Note trans the values in need to be able to be valid as a key name, such as an integer or string. If the value is of the wrong type, a warning will be issued and the problematic key/value pair will not be reversed .
If the same value occurs more than once, the last key will be its value, and all the others are lost.
Parameters
-
trans
-
An array of key/value pairs to exchange.
return value
On success, returns an array after the interchange if it fails NULL .
Example
Example #1 array_flip () example
<?php
$trans = array_flip($trans);
$original = strtr($str, $trans);
?>
Example #2 Array_flip () Example: conflict
<?php
$trans = array("a" => 1, "b" => 1, "c" => 2);
$trans = array_flip($trans);
print_r($trans);
?>
Now $trans it is:
Array ( [1] = b [2] = c)
PHP Array_flip () method