Easy Tutorial
❮ Home Php Superglobals ❯

PHP range() Function

Complete PHP Array Reference Manual

Example

Create an array containing elements from "0" to "5":


Definition and Usage

The range() function creates an array containing a range of elements.

The function returns an array of elements from low to high.

Note: If the low parameter is greater than the high parameter, the array will be created from high to low.


Syntax

Parameter Description
low Required. Specifies the minimum value of the array elements.
high Required. Specifies the maximum value of the array elements.
step Optional. Specifies the increment between each element. Default is 1.

Technical Details

Return Value: Returns an array of elements from low to high.
PHP Version: 4+
--- ---
Changelog: The step parameter was added in PHP 5.0. <br> <br>In versions PHP 4.1.0 to 4.3.2, the function treated numeric strings as strings rather than integers. Numeric strings were used for character sequences, for example, "5252" was treated as "5". <br> <br>Support for character sequences and descending arrays was added in PHP 4.1.0. The values of character sequences are limited to a single length. If the length is greater than one, only the first character is used. Prior to this version, range() only generated ascending integer arrays.
--- ---

More Examples

Example 1

Return an array containing elements from "0" to "50" incremented by 10:

Example 2

Using letters - return an array containing elements from "a" to "d":


❮ Home Php Superglobals ❯