Flipping Array Keys and Values in PHP


Swap the keys and values of an array using array_flip().

Source Code

$array = ["a" => 1, "b" => 2, "c" => 3];
$flipped = array_flip($array);
print_r($flipped); // Keys become values and values become keys
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments