3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array( "0" => "red", "1" => "green" , "2" => "red" , "3" => "blue", "4" => "blue", "5" => "blue" ); $group_by_data = array_count_values($a); $keys = []; foreach($a as $key => $color){ if($group_by_data[$color] > 1){ if(!isset($keys[$color])) $keys[$color] = []; $keys[$color][] = $key; } } print_r($keys);

preferences:
30.5 ms | 405 KiB | 5 Q