lekalili
lekalili

Reputation: 11

Loop through numbers with a step - PHP

I'm new on programming and I've tried to print a list of numbers with a step of 3, basically the first number remains the same 3 times but the second one increments 3 times. Here is pattern i want to achieve:

01-01
01-02
01-03
02-01
02-02
02-03
...
11-01
11-02
11-03
12-01
...

What I've tried so far:

for($a=0; $a <= 3; $a++){
   for($b=1; $b <= 3; $b++){
       echo $a.$b. "-" .$a.$b."<br";
   }
}

My Output:

01-01
02-02
03-03

Any idea on how to print the first element 3 times before incrementing? Thanks.

Upvotes: 1

Views: 99

Answers (1)

Dum
Dum

Reputation: 1501

$to = 15; // to what number
for($a=1; $a <= $to; $a++){ // this loop will take number from 1 to $to
   for($b=1; $b <= 3; $b++){ //this loop will do the printing three times
       echo $a. "-" .$b."<br";
   }
}

Hope this helpful. :)

Upvotes: 1

Related Questions