English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP range() Function Usage and Example

PHP Array Function Manual

The range() function creates an array based on a range, including the specified elements

Syntax

range ($low, $high[, $step]);

Definition and Usage

This function returns fromlowtohighof elements (including low and high values) in the array. If low > high, the order will be from high to low.

Parameter

Serial NumberParameters 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

Return Value

It returns an array of elements, returning an array of elements from low to high (including low and high).

Online Example

<?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

   PHP Array Function Manual