Hello folks! welcome back to a new section of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP range() Function.
The PHP range() function returns an array of elements from low to high, inclusive. If the low parameter is greater than the high parameter, the sequence will be from high to low.
The PHP range() function returns an array of elements from low to high, inclusive. If the low parameter is greater than the high parameter, the sequence will be from high to low.
Syntax
Following below is the syntax to use this function -
range ( $low, $high [, $step] );
READ: PHP | prev() Function
Parameter Details
Sr.No | Parameter & Description |
---|---|
1 | low(Required) This is a lower range of the array |
2 | high(Required) This is a upper range of the array |
3 | step(Optional) Steps to increase array element. By default it is 1 |
Return Value
This function returns an array of elements.
Example
Try out the below 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"; ?>
Output
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
READ: PHP | pos() Function
Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP reset() Function.
Feel free to ask your questions where necessary and we 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.
Feel free to ask your questions where necessary and we 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.