public static function getBestDivisor($rows, $options = null)
    {
        $options = static::getOptions($options, [
            "min"   =>  5,
            "max"   =>  10,
        ]);

        if ($rows <= $options["max"]) {
            return $rows;
        }

        $divisor = false;
        $divisorDiff = false;

        for ($i = $options["max"]; $i >= $options["min"]; $i--) {
            $remain = $rows % $i;

            # Calculate how close the remainder is to the postentional divisor
            $quality = $i - $remain;

            # If no divisor has been set yet then set it to this one, and record it's quality
            if (!$num) {
                $divisor = $i;
                $divisorQuality = $quality;
                continue;
            }

            # If the potentional divisor is a better match than the currently selected one then select it instead
            if ($quality < $divisorQuality) {
                $divisor = $i;
                $divisorQuality = $quality;
            }
        }

        return $divisor;
    }
public static function getBestDivisor($rows, $options = null)
    {
        $options = static::getOptions($options, [
            "min"   =>  5,
            "max"   =>  10,
        ]);

        if ($rows <= $options["max"]) {
            return $rows;
        }

        $divisor = false;
        $divisorDiff = false;

        for ($i = $options["max"]; $i >= $options["min"]; $i--) {
            $remain = $rows % $i;

            # Calculate how close the remainder is to the postentional divisor
            $quality = $i - $remain;

            # If no divisor has been set yet then set it to this one, and record it's quality
            if (!$num) {
                $divisor = $i;
                $divisorQuality = $quality;
                continue;
            }

            # If the potentional divisor is a better match than the currently selected one then select it instead
            if ($quality < $divisorQuality) {
                $divisor = $i;
                $divisorQuality = $quality;
            }
        }

        return $divisor;
    }
public static function getBestDivisor ( $ rows , $ options = null ) { $ options = static :: getOptions ( $ options , [ "min" => 5 , "max" => 10 , ] ) ; if ( $ rows <= $ options [ "max" ] ) { return $ rows ; } $ divisor = false ; $ divisorDiff = false ; for ( $ i = $ options [ "max" ] ; $ i >= $ options [ "min" ] ; $ i -- ) { $ remain = $ rows % $ i ; # Calculate how close the remainder is to the postentional divisor $ quality = $ i - $ remain ; # If no divisor has been set yet then set it to this one, and record it's quality if ( ! $ num ) { $ divisor = $ i ; $ divisorQuality = $ quality ; continue ; } # If the potentional divisor is a better match than the currently selected one then select it instead if ( $ quality < $ divisorQuality ) { $ divisor = $ i ; $ divisorQuality = $ quality ; } } return $ divisor ; }
Calculate the most reasonable divisor for a total.
Useful for repeating headers in a table with many rows.

$options:
- int "min" The minimum number of rows to allow before breaking (default: 5)
- int "max" The maximum number of rows to allow before breaking (default: 10)

@param int $rows The total number to calculate from (eg, total number of rows in a table)
@param array $options An array of options (see above)

@return int
Calculate the most reasonable divisor for a total . Useful for repeating headers in a table with many rows .