PHP: range() function
PHP: Create an array containing a range of elements
The range() function used to create an array containing a range of elements.
Version:
(PHP 4 and above)
Syntax:
range(low_value, high_value, step)
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
low_value | Specify the lowest value. | Required | Mixed* |
high_value | Specify the highest value. | Required | Mixed* |
step | It is used as increment between elements. The default value is 1. | Optional | Integer/Float |
*Mixed: Mixed indicates multiple (but not necessarily all) types.
Return value: An array.
Value Type : Array
Example:
<?php
$number_list = range(11,19);
print_r ($number_list);
echo "<br /> ";
$number_list_step = range(11,19,2);
print_r ($number_list_step);
echo "<br /> ";
$letter_list = range("u","z");
print_r ($letter_list);
?>
Output:
Array ( [0] => 11 [1] => 12 [2] => 13 [3] => 14 [4] => 15 [5] => 16 [6] => 17 [7] => 18 [8] => 19 ) Array ( [0] => 11 [1] => 13 [2] => 15 [3] => 17 [4] => 19) Array ( [0] => u [1] => v [2] => w [3] => x [4] => y [5] => z)
Pictorial Presentation:
View the example in the browser
Practice here online :
See also
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/php/function-reference/range.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics