RE: [PHP] Finding Mode

From: Date: Sun, 08 Dec 2002 14:12:53 +0000
Subject: RE: [PHP] Finding Mode
Groups: php.general 
Request: Send a blank email to php-general+get-127430@lists.php.net to get a copy of this message
> -----Original Message----- > From: Rick Widmer > > At 07:12 PM 12/7/02 -0500, Stephen wrote: > >Another math question... How would I find the mode (number that repeats most > >often) of an array? Then, if there isn't a number that repeats most often, > >tell the user that. > > For each entry in the array, count the number of times a value occurs: > > while( list( , $Value ) = each( $MyArray )) { > $NumberHits[ $Value ] ++; > } Or use the built-in function: $NumberHits = array_count_values($MyArray); Cheers! Mike

« previous php.general (#127430) next »