循环并返回开始

I would like to get this result:

0 1
1 1
2 1
3 1
...
19 1

0 2
1 2
2 2
3 2
...
19 2

...

0 10
1 10
2 10
3 10
...
19 10

but i don't know what i'm doing wrong, using this code:

$p=0;
for($i=0; $i<40; $i++)
{
    if($i%20 == 0)
    {
        $p+=1;
        $i=0;
    } else {
        echo $i.' '.$p;
        echo '<br>';
    }
}

When i try to run the code, it takes forever. What am i doing wrong? Please help me. Thanks.

You should use nested for loops

for($i = 1; $i <= 10; $i++) {
    for($j = 0; $j < 20; $j++)
        echo $j . ' ' . $i . '<br>';

    echo '<br>';
}