1<?php
2 // range($start, $end [,$steps])
3 $numbers = range(0, 5);
4 print_r($numbers);
5 // Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 )
6
7 $numbers2 = range(0, 5, 2);
8 print_r($numbers2);
9 //Array ( [0] => 0 [1] => 2 [2] => 4 )
10
11
12 ?>
1
2<?php
3// array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
4foreach (range(0, 12) as $number) {
5 echo $number;
6}
7
8// The step parameter
9// array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
10foreach (range(0, 100, 10) as $number) {
11 echo $number;
12}
13
14// Usage of character sequences
15// array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i');
16foreach (range('a', 'i') as $letter) {
17 echo $letter;
18}
19// array('c', 'b', 'a');
20foreach (range('c', 'a') as $letter) {
21 echo $letter;
22}
23?>
24
25