note 95102 added to function.array-sum
| From: | TimWhite at osu1 dot php dot net | Date: | Mon, 14 Dec 2009 00:34:34 +0000 |
| Subject: | note 95102 added to function.array-sum | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-163910@lists.php.net to get a copy of this message | ||
In reference to jodymickey's array_mode function...
This function returns the mode(s) of an array (and not the number of times the value actually
occured).
An array is always the returned result.
This function does *not* suffer from the same problem in that if there is more than one mode, it
will return only one.
<?php
/**
* array_mode
*
* @param array $list
* @static
* @access public
* @return array
*/
public static function array_mode(array $list)
{
$list = array_count_values($list);
asort($list, SORT_NUMERIC);
$result = array();
end($list);
while (! is_null($key = key($list)) ) {
if (isset($current) && ($current > current($list))) break;
$current = current($list);
$result[] = $key;
prev($list);
}
return $result;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 24.255.15.144
----
Manual Page -- http://www.php.net/manual/en/function.array-sum.php
Edit -- https://master.php.net/note/edit/95102
Del: integrated -- https://master.php.net/note/delete/95102/integrated
Del: useless -- https://master.php.net/note/delete/95102/useless
Del: bad code -- https://master.php.net/note/delete/95102/bad+code
Del: spam -- https://master.php.net/note/delete/95102/spam
Del: non-english -- https://master.php.net/note/delete/95102/non-english
Del: in docs -- https://master.php.net/note/delete/95102/in+docs
Del: other reasons-- https://master.php.net/note/delete/95102
Reject -- https://master.php.net/note/reject/95102
Search -- https://master.php.net/manage/user-notes.php