I need to sort an array by quantity of duplicate values.
Here's an example:
$arr = array(
1=> 'Love is true',
2=> 'Love is true',
3=> 'Hello Word',
4=> 'Hello Word',
5=> 'Hope',
6=> 'Hope',
7=> 'Love is true',
8=> 'Hello Word',
9=> 'Hello Word',
10=>'Hope',
11=>'Hello Word',
12=>'Hope',
13=>'Hello Word',
14=>'Hello Word',
15=>'Hello Word');
print_r($arr);
In this array, we can see that
Love is true > duplicate > 3x Hello Word > duplicate > 8x Hope > duplicate > 4x
I'd like the sorting to put the values that repeat the most first:
Hello Word position 1# In array (repeats 8 times) Hope 2# In array (repeats 4 times) Love is true 3# In array (repeats 3 times)
So it returns this array:
Array
(
[0] => Hello Word
[1] => Hope
[2] = Love is true
)