note 55767 added to function.array-sum

From: Date: Fri, 12 Aug 2005 16:22:03 +0000
Subject: note 55767 added to function.array-sum
Groups: php.notes 
Request: Send a blank email to php-notes+get-93510@lists.php.net to get a copy of this message
Not sure where else to put this, but I added something that determines the most commonly occuring item in an array. Known Bugs: It will always return the first value if no mode are found, and the first mode found if more are found of same or lesser count. <?php function array_mode($array) { $count = array(); foreach ($array as $item) { $count[$item]++; } $mostcommon = ""; $iter = 0; foreach ($count as $k => $v) { if ($v > $iter) { $mostcommon = $k; $iter = $v; } } return array("mode" => $mostcommon, "count" => $count[$mostcommon]); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.array-sum.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55767 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55767&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55767&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55767&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55767&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55767&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55767&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55767&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93510) next »