Skip to content

RangeIterator

github-actions edited this page Mar 31, 2026 · 2 revisions

An iterator that behaves like PHP's range() function.

It supports both ascending and descending sequences and allows iteration over floating-point or integer ranges.

Usage Example:


  • Full name: \FastForward\Iterator\RangeIterator
  • This class implements: Iterator, Countable

Methods

__construct

Initializes the RangeIterator.

public __construct(float|int $start, float|int $end, float|int $step = 1, bool $includeBoundary = false): mixed

Parameters:

Parameter Type Description
$start float|int the starting value of the range
$end float|int the ending value of the range
$step float|int the step size between values (must be positive)
$includeBoundary bool whether the iterator should force the end value when the next step would overshoot it

Throws:

if step is non-positive or greater than the range size


current

Returns the current value in the range.

public current(): float|int

Return Value:

the current value


key

Returns the current key (index).

public key(): int

Return Value:

the current index in the iteration


next

Moves to the next value in the range.

public next(): void

rewind

Resets the iterator to the start of the range.

public rewind(): void

valid

Checks if the current position is within the valid range.

public valid(): bool

Return Value:

true if the current value is within the valid range, false otherwise


count

Counts the total number of steps in the range.

public count(): int

Return Value:

the number of elements in the range


Clone this wiki locally