- print_r: documentation ( source)
<?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);