PHP range array function

Last Updated: February 21, 2022

range – Create an array with range

Syntax

range(string|int|float $start, string|int|float $end, int|float $step = 1): array

Supports (PHP 4 , PHP 5, PHP 7, PHP 8)

Parameters

Parameter Description
start first value of sequence
end last value of sequence
step step value for the sequnce. It can be increment or decrement value

Return Value

Return the value of the array of the previous location. If no element is found it will return false

Example

foreach (range(0, 5) as $number) {
    echo $number;
}

Output

012345

Test