PHP | range() Function

PHP range() Function

Hello dear readers! welcome back to another section of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP range() Function.

PHP range() function returns an array of elements from low to high, inclusive. If the low parameter is greater than high parameter, the sequence will be from high to low.


Following below is the syntax to use this function -

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

Parameter Details

Sr.NoParameter & Description


This is a lower range of the array



This is a upper range of the array



Steps to increase array element. By default it is 1

Return Value

This function returns an array of elements.


Try out the below example -

   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";


When the above code is executed, it will produce the following 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

Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about the PHP reset() Function.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.