3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 2 => 'John', 21 => 'John', 32 => 'Joe', 42 => 'John', 23 => 'Joe', 62 => 'John', 25 => 'Joe', ); $flipped = []; foreach($arr AS $key => $value) { $flipped[$value][] = $key; } print_r($flipped);

preferences:
24.01 ms | 404 KiB | 5 Q