I would like to delete all unique values from an array.
So lets say I have $array = (1,2,3,5,4,3,4,5,234)
the function should delete all unique values and output:
JavaScript
x
$newarray = (3,5,4,3,4,5)
I just thought of a solution with array_count_values
but I do not know how I could iterate it. Furthermore I am sure there is a more elegant and efficient way to do this. Thank you for your help in advance.
Advertisement
Answer
One of solutions:
JavaScript
$array = [1,2,3,5,4,3,4,5,234];
$freq = array_count_values($array);
print_r(array_filter(
$array,
function ($v) use ($freq) { return 1 < $freq[$v]; }
));