the only problem there is that sort() overwrites the array keys...
This works, and unfortunately I don't think there's a quicker way...
PHP Code:
$a = array("red", "green", "blue", "blue", "yellow", "yellow", "yellow");
$b = array_count_values( $a );
arsort( $b );
$c = array_flip( $b );
$first = array_shift( $c );
$second = array_shift( $c );
$third = array_shift( $c );
print "Most frequent value is $first<br>Second is $second<br>Third is $third";
// Outputs:
/*
Most frequent value is yellow
Second is blue
Third is red
*/
note, however, how the "tie" between green and red is handled
that would be even more complex to deal with...
Bookmarks