Right now, I’m trying to print the numbers in between two ranges assume 1 to 48 and 114 to 118 using a for loop.
I tried the following to do this :
for ($y = 1; $y < 48; $y++) { }
The loop printed numbers in the range 1 to 48 correctly.
But I haven’t a clear idea to apply the second range 114 to 118 to print numbers as 115, 116 and 117 in another range.
I want to print the numbers as 1,2,3,……………..45,46,47,115,116,117
Anyone can help on this for me ?
3
Answers
One of the ways is: use a conditional statment to print what you want to include
See demo
For a solution that is both efficient and easy to read you could use something like this:
This makes use of range(), the the
...
operator, short array notation, and foreach.See: https://3v4l.org/l8ril