Generate an array with elements ranging from “0” to “5”.
<?php $number = range(0,5); print_r ($number); ?> |
The range()
function generates an array of elements within a specified range.
This function returns an array starting from the low value up to the high value.
Note: If the low parameter is greater than the high parameter, the array will be created in reverse order, from high to low.
range(low, high, step) |
Parameter |
Description |
low |
Required. Specifies the minimum value for the array. |
high |
Required. Specifies the maximum value for the array. |
step |
Optional. Specifies the increment for the range. The default value is 1. |
Return Value: |
Returns an array with elements ranging from the low value to the high value. |
PHP Version: |
4+ |
PHP Changelog: |
The In PHP versions 4.1.0 through 4.3.2, this function treats numeric strings as strings rather than integers. For example, “5252” is processed as “5” when generating character sequences. Support for character sequences and decrementing arrays was added in PHP 4.1.0. Character sequences are limited to a single character; if the length exceeds one, only the first character is used. Prior to this version, |
Return an array of elements ranging from “0” to “50”, with an increment of 10.
<?php $number = range(0,50,10); print_r ($number); ?> |
Using letters, return an array of elements ranging from “a” to “d”.
<?php $letter = range(“a”,“d”); print_r ($letter); ?> |