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