Javatpoint Logo
Javatpoint Logo

PHP range() function

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

Parameter Description Is compulsory
low It is a lower range of the array. compulsory
high It is an upper range of the array. compulsory
step Steps 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
)





Help Others, Please Share

facebook twitter pinterest