How to use range() function in php?

The range() function is an inbuilt function in PHP which is used to create an array of elements of any kind such as integer, alphabets within a given range(from low to high) i.e, list’s first element is considered as low and last one is considered as high.

1. Code:

<?php
$arr = range('p','a');
  
echo"Array for range('p','a'): "."<br>";
print_r($arr);
echo"<br>";
$arr1 = range(0,10,2);
  
echo"Array for range(0,10,2): "."<br>";
print_r($arr1);

?>

2. Example:

Input:

$arr = range('p','a');
$arr1 = range(0,10,2);

Output:

Array for range('p','a'):
Array ( [0] => p [1] => o [2] => n [3] => m [4] => l [5] => k [6] => j [7] => i [8] => h [9] => g [10] => f [11] => e [12] => d [13] => c [14] => b [15] => a )
Array for range(0,10,2):
Array ( [0] => 0 [1] => 2 [2] => 4 [3] => 6 [4] => 8 [5] => 10 ) 

3. Syntax:

array range(low, high, step)

Parameters:

  1. low: It will be the first value in the array generated by range() function.
  2. high: It will be the last value in the array generated by range() function.
  3. step: It is used when the increment used in the range and it’s default value is 1.