PHP range() function
The range() function returns an array of consecutive character values or integers between and including the two values that are passed as parameters.
Syntax:
This method accepts three parameters.
Parameters | Values |
start | The first or lowest value of an array to be generated. |
end | The last or highest value of an array to be generated. |
step(optional) | default value is 1, if given it is used as the value to increment or decrement by range to generate a sequence, it can not be 0 or outside the start and end parameters. |
Return Value: An array consists of consecutive characters or integers between the start and end parameters.
The following example generates an array of numeric values.
$arraynumbers = range(3, 9); // It returns array(3, 4, 5, 6, 7, 8, 9);
print_r ($arraynumbers);
Output:
The following example generates an array of alphabets.
$arrayletters = range('a', 'z'); // Alphabets from A to Z
print_r ($arrayletters);
Output:
The following example generates reversed numbers.
$arrayrevnumbers = range(4, 1); // it returns array(4, 3, 2, 1);
print_r ($arrayrevnumbers);
Output: