Jyxo\Spl\ArrayUtil::range PHP Method

range() public static method

Params $low and $high are inclusive. If $low > $high, resulting array will be in descending order.
public static range ( mixed $low, mixed $high, Closure $step, Closure $compare = null ) : array
$low mixed Minimal value
$high mixed Maximal value
$step Closure Closure which creates next value from current
$compare Closure comparing closure for detecting if we're at the end of the range (Optional)
return array
    public static function range($low, $high, \Closure $step, \Closure $compare = null) : array
    {
        $data = [$low];
        $stepDown = $low > $high;
        $compare = $compare ?: function ($a, $b) use($stepDown) {
            return $stepDown ? $a > $b : $a < $b;
        };
        $current = $low;
        while ($compare($current, $high)) {
            $data[] = $current = $step($current);
        }
        return $data;
    }