src/Statistics.php
public static function mode($values)
    {
        $frequency = self::frequency($values);

        if (count($frequency) === 1) {
            return key($frequency);
        }

        $lastTwo = array_slice($frequency, -2, 2, true);
        $firstFrequency = current($lastTwo);
        $lastFrequency = next($lastTwo);

        if ($firstFrequency !== $lastFrequency) {
            return key($lastTwo);
        }

        throw new StatisticsError('There is not exactly one most common value.');
    }
public static function mode($values)
    {
        $frequency = self::frequency($values);

        if (count($frequency) === 1) {
            return key($frequency);
        }

        $lastTwo = array_slice($frequency, -2, 2, true);
        $firstFrequency = current($lastTwo);
        $lastFrequency = next($lastTwo);

        if ($firstFrequency !== $lastFrequency) {
            return key($lastTwo);
        }

        throw new StatisticsError('There is not exactly one most common value.');
    }
public static function mode ( $ values ) { $ frequency = self :: frequency ( $ values ) ; if ( count ( $ frequency ) === 1 ) { return key ( $ frequency ) ; } $ lastTwo = array_slice ( $ frequency , - 2 , 2 , true ) ; $ firstFrequency = current ( $ lastTwo ) ; $ lastFrequency = next ( $ lastTwo ) ; if ( $ firstFrequency !== $ lastFrequency ) { return key ( $ lastTwo ) ; } throw new StatisticsError ( 'There is not exactly one most common value.' ) ; }
Calculates the mode for a given set of values.

@param array $values The input values
@return float|int The mode of values as an integer or float
@throws \Oefenweb\Statistics\StatisticsError
Calculates the mode for a given set of values .