Create an array containing elements from "0" to "5":
<?php$number = range(0,5);print_r ($number);?>The range() function creates an array containing a specified range of elements.
This function returns an array containing elements from low to high.
Note: If the low parameter is greater than the high parameter, the array created will be from high to low.
range( low,high,step )
parameter | describe |
---|---|
low | Required. Specifies the minimum value of an array element. |
high | Required. Specifies the maximum value of an array element. |
step | Optional. Specifies the stepping between elements. The default is 1. |
Return value: | Returns an array containing elements from low to high . |
---|---|
PHP version: | 4+ |
Update log: | The step parameter is new in PHP 5.0. In PHP versions 4.1.0 to 4.3.2, this function treats numeric strings as strings instead of integers. Numeric strings will be used for character sequences, for example, "5252" is treated as "5". Support for character sequences and descending arrays was new in PHP 4.1.0. Character sequence values are limited to a length. If the length is greater than one, only the first character is used. Prior to this version, range() only produced increasing arrays of integers. |
Returns an array containing elements from "0" to "50" in increments of 10:
<?php$number = range(0,50,10);print_r ($number);?>Using letters - Returns an array containing elements from "a" to "d":
<?php$letter = range("a","d");print_r ($letter);?>