如何按出现次数的顺序列出数组的元素?

I have an array like this.

$array = array(
'Element1', 
'Element2', 
'Element3', 
'Element1', 
'Element1', 
'Element4', 
'Element4', 
'Element2', 
'Element2', 
'Element2', 
'Element2', 
'Element4', 
'Element5', 
'Element5' );

I want an array like this as output.

$output = array('Element2' , 'Element1', 'Element4', 'Element5', 'Element3');

So, what i want is:

  1. Remove all the elements from the array which repeat.
  2. Order the output array in such manner that the element which occured most in the input array is on top.

It should be ok:

$numbers = array_count_values($array);

arsort($numbers); // Thanks Jessica!
$result = array_keys($numbers);

Your expected output is contradictory to your requirements listed. Element5 should come before Element3

<pre>
<?php
$values = array(
'Element1', 
'Element2', 
'Element3', 
'Element1', 
'Element1', 
'Element4', 
'Element4', 
'Element2', 
'Element2', 
'Element2', 
'Element2', 
'Element4', 
'Element5', 
'Element5' );

$result = array_count_values($values);
arsort($result);
$result = array_keys($result);
print_r($result);
?>