PHP range() Function
PHP range() Function
The range () function in PHP is used to create an array containing a range of elements.
Syntax
range ( mixed $start , mixed $end [, number $step = 1 ] )
Parameter
start(required)- This parameter represents the first value of the sequence.
end(required)- This parameter represents the last sequence value that is ended upon reaching the end value.
step(optional)- This parameter represents a value used as the increment between elements in the sequence. It should be a positive number, and its default value is 1.
Return
This parameter returns an array of elements from start to end.
Example 1
Output
0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8
Example 2
Output
0 20 40
Example 3
Output
e f g h i j k l m
Example 4
Output
e j o t y
Example 5
Output
PHP Warning: range(): step exceeds the specified range in /workspace/Main.php on line 3 PHP Warning: Invalid argument supplied for foreach() in /workspace/Main.php on line 6
Example 6
Output
Even number: 10 8 6 4 2 0