range
Create an array containing a range of elements.
range Function synopsis
range(
string|int|float $start,
string|int|float $end,
int|float $step = 1
): array
Parameters
$start
Typestring|int|float
First value of the sequence.
$end
Typestring|int|float
Last possible value of the sequence.
$step
OptionalTypeint|floatDefault value1
$step indicates by how much is the produced
sequence progressed between values of the sequence.
Return value
Typearray
Returns a sequence of elements as an array with the first
element being $start going up to
$end, with each value of the sequence being
$step values apart.
The last element of the returned array is either $end
or the previous element of the sequence,
depending on the value of $step.
If both $start and $end are
strings, and $step is int
the produced array will be a sequence of bytes,
generally latin ASCII characters.
If at least one of $start, $end,
or $step is float
the produced array will be a sequence of float.
Otherwise, the produced array will be a sequence of int.
Changes to the range Function
PHP 8.3
- Parameter type added for parameter #1 (
$start):string|int|float - Parameter type added for parameter #2 (
$end):string|int|float
range(
- $start,
+ string|int|float $start,
- $end,
+ string|int|float $end,
int|float $step = 1
): array PHP 8.0
- Return type added:
array - Parameter name of parameter #1 changed:
$lowto$start - Parameter name of parameter #2 changed:
$highto$end - Parameter type added for parameter #3 (
$step):int|float - Parameter default value added for position #3 (
$step):1
range(
- $low,
+ $start,
- $high,
+ $end,
- $step
+ int|float $step = 1
- )
+ ): array range Function Availability
range Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |