note 55767 deleted from function.array-sum by levim

From: Date: Tue, 18 Mar 2014 19:42:01 +0000
Subject: note 55767 deleted from function.array-sum by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198963@lists.php.net to get a copy of this message
Note Submitter: KageKonjou at GMail dot com ---- 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]); } ?>

« previous php.notes (#198963) next »