In python we have:
for i in range(length)
What about PHP?
Straight from docs:
foreach (range(0, 12) as $number) { echo $number; }
Old fashioned for loops:
for
for ($i = 0; $i < length; $i++) { // ... }
Or use foreach with a function :
foreach (range(1, 10) as $i) { // ... }
for ($i = 0; $i < LENGTH_GOES_HERE; $i++) { ... }
or
foreach (range(0, LENGTH_GOES_HERE - 1) as $i) { ... } , cf. range () .
foreach (range(0, LENGTH_GOES_HERE - 1) as $i) { ... }
There is a range function in php, you can use this.
foreach( range(0,10) as $y){ //do something }
but unlike python, you have to pass 2 parameters, range (10) will not work.
Try the following:
// Generates the digits in base 10. // array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) foreach (range(0, 9) as $number) { echo $number; }