PHP range
Last Updated on Feb 15, 2023
Range
Range is a function that creates an array containing the range of elements
It takes 3 arguments
range(start,end,step)
Start is the first value
End is the last value
Step is the increment between first and last values default is 1
So let’s see some examples
A sequence of numbers between 1 and 6
$range = range(1,6);
print_r($range);
// Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 )
A sequence of numbers between 1 and 6 with increments of 2 (step 2)
$range = range(1,6,2);
print_r($range);
// Array ( [0] => 1 [1] => 3 [2] => 5 )
Conclusion
Now you know range funciton in PHP.
I recommend you to open a PHP file and try to define different ranges. Then try different steps for all those ranges.
If you have any suggestions, questions, or opinions, please contact me. I’m looking forward to hearing from you!
Key takeaways
- range function in php
- steps in a range