Home >>PHP Array Functions >PHP range() Function
PHP range() function is used to create an array of elements of any kind such as integer, alphabets within a given range. It accepts three parameters $low, $high, and $step. It returns an array of elements from $low to $high as output.
Syntax:
range($low, $high, $step);
Parameter | Description |
---|---|
low | This is a required parameter. It defines the lowest value of the array. |
high | This is a required parameter. It defines the highest value of the array. |
step | This is an optional parameter. It defines the increment used in the range. |
Here is an example of range() function in PHP:
<html> <body> <pre> <?php $number = range(0,9); print_r ($number); ?> </pre> </body> </html>
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 )
Example 2:
<html> <body> <pre> <?php $number = range(0,100,11); print_r ($number); ?> </pre> </body> </html>
Array ( [0] => 0 [1] => 11 [2] => 22 [3] => 33 [4] => 44 [5] => 55 [6] => 66 [7] => 77 [8] => 88 [9] => 99 )