note 13793 deleted from function.array by irc-html

From: Date: Sat, 19 Jan 2002 20:55:24 +0000
Subject: note 13793 deleted from function.array by irc-html
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-25436@lists.php.net to get a copy of this message
I was needing to find the mathematical mode of a list of numbers. Here's a quick function I threw together: function array_mode($haystack) { for($i=0;$i<sizeof($haystack);$i++) { $needle = $haystack[$i]; $count[$needle]++; } arsort($count,SORT_NUMERIC); while (list ($key, $val) = each ($count)) { return $key; } } Anyone know of an easier or better way of doing this? I think this works, but I haven't done too much testing.

« previous php.notes (#25436) next »