REPEAT NUMBERS EVERY 4 TIMES IN PHP

Asked

Viewed 121 times

-3

Hello, sorry for the ignorance is that I am now entering the back-end and I need a 'for' that repeats the same number of 4 in 4, at each repetition it increments, receives one more FOR EXAMPLE:

MUST PRINT LIKE THIS:

111222333444555666777...

Here’s the code that’s not working:

    $x=0;
    for ($i = 1; $i <= 28; $i++) {
        if($x<=4){
        $x++;
        echo $x;

    }else{
       $x=0;
       $i=$i-1;  
     }
  }

1 answer

2


for ($i = 1; $i <= 28; $i++) {
    echo "$i$i$i";
}

Thus?

  • 1

    What is the value of $x? This code will not compile. I believe you wanted to use $i in place of $x.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.