PHP range() Function

6 Jan 2025 | 1 min read

The PHP range( ) function is used to create an array containing a range of elements. The PHP range( ) function returns an array of elements from low to high. This function was introduced in PHP 4.0.

Syntax

Parameter

ParameterDescriptionIs compulsory
lowIt is a lower range of the array.compulsory
highIt is an upper range of the array.compulsory
stepSteps to increase array element. By default it is 1.Optional

Returns

The range( ) function returns array of elements.

Example 1

Output:

 ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) 

Example 2

Output:

 Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => g ) 

Example 3

Output:

 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 

Example 4

Output:

 ( [0] => z [1] => y [2] => x [3] => w [4] => v [5] => u )