English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The range() function creates an array based on a range, including the specified elements
range ($low, $high[, $step]);
This function returns fromlowtohighof elements (including low and high values) in the array. If low > high, the order will be from high to low.
Serial Number | Parameters and Description |
---|---|
1 | low(Required) This is the lower limit of the array |
2 | high(Required) This is the upper limit of the array |
3 | step(Optional) Steps to add array elements. The default is1 |
It returns an array of elements, returning an array of elements from low to high (including low and high).
<?php foreach (range(0, 6) as $number) { echo "$number, "; } print "\n"; foreach (range(0, 100, 10) as $number) { echo "$number, "; } print "\n"; foreach (range('a', 'c') as $letter) { echo "$letter, "; } print "\n"; foreach (range('f', 'a') as $letter) { echo "$letter, "; } print "\n"; ?>Test and See‹/›
Output Result:
0, 1, 2, 3, 4, 5, 6, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 a, b, c, f,e,d,c, b, a