To switch the position of keys and corresponding values in each element of an array, use the PHP function array_flip():
$a = array('1' => 'a', '2' => 'b', '3' => 'c');
$b = array_flip($a);
print_r($b);
And the output would be:
Array
(
[a] => 1
[b] => 2
[c] => 3
)
You should also read:
- PHP: Find and Return the Minimum (Lowest) Value or Maximum (Highest) Value of Several Numbers
- PHP: Create an Array
- PHP: Change Array Key Case – All Array Keys to Lowercase or Uppercase
- PHP: Count the Number of Occurrences of Each Unique Value in an Array
- How to get all the sub-directories of a given directory in PHP?


Facebook
Twitter
Google Plus