Mysterious Mysterious - 1 month ago 7
PHP Question

split a number into equal part

I have a for loop and i want to show the numbers equal parts.

Here is my code-

for($j = 1; $j <= 8; $j++){
echo ($j%4)."<br/>";
}


I want output like-

1
2
3
4
1
2
3
4

Answer

You were close to the solution:

<?php
for($j = 0; $j < 8; $j++){
    echo ($j % 4 + 1)."<br/>";
}