range

(PHP 3>= 3.0.8, PHP 4 >= 4.0.0)

range --  Create an array containing a range of elements

Description

array range (mixed low, mixed high)

range() returns an array of elements from low to high, inclusive. If low > high, the sequence will be from high to low.

Example 1. range() examples


foreach(range(0, 9) as $number) {
    echo $number;
}
foreach(range('a', 'z') as $letter) {
    echo $letter;
}
foreach(range('z', 'a') as $letter) {
    echo $letter;
}
      

Note: Prior to version 4.1.0 the range() function only generated incrementing integer arrays. Support for character sequences and decrementing arrays was added in 4.1.0.

See shuffle() for another example of its use.