3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Everything you enter here will be executed by our servers. Try it! $arr = array(10,8,13,8,5,10,10,12); $occurrences = array_count_values($arr); usort($arr, function ($a, $b) use ($occurrences) { // if the occurrence is equal (== 0), return value difference instead return ($occurrences[$a] - $occurrences[$b]) ?: ($a - $b); }); print_r($arr);

preferences:
40.38 ms | 402 KiB | 5 Q