3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array(45, 5, 1, 22, 22, 10, 10); //use array_count_values to counts all the values of an array. $get_repeated_value = array_count_values($array); $final_array = array(); foreach($get_repeated_value as $key => $value){ //If value is repeated, get the index of that values from array. if($value > 1){ $final_array[$key] = array_keys($array, $key); } } echo "<pre>"; print_r($final_array); ?>
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
<pre>Array ( [22] => Array ( [0] => 3 [1] => 4 ) [10] => Array ( [0] => 5 [1] => 6 ) )

preferences:
158.47 ms | 408 KiB | 5 Q