Triangle style output, incrementing max line length The output that I want:


  
  1
  2 3
  4 5 6
  7 8 9 10
  11 12 13 14 15
  16 17 18 19 20 21
  22 23 24 25 26 27 28
  


&lt;ul&gt;
    &lt;li&gt;
        &lt;?php
        $i;
        $a = 1;
        $b = 0;

        for($i = 1; $i &lt; 29; $i++){
          echo $i;

          if ($i == $a){
            echo "&lt;/li&gt;&lt;li&gt;";

            $a = $i + 2 + $b;
            $b++;
          }
       }
       ?&gt;
    &lt;/li&gt;   
&lt;/ul&gt;


Is it possible to get rid of $b and make it simpler ?
The output of your program is not as you are saying. This is the real output:

1
23
456
78910
1112131415
161718192021
22232425262728


To get your desired output, you can change this:
echo $i;

To:
echo $i.&quot; &quot;;

This will append the extra space after each iteration.

$a
a is a poor variable name. You could make your code much clearer if you gave it a meaningful name, like $countOfNumbersToDisplay. Sure, it's a lot longer to type, but it indicates your intention much more clearly than $a.
Same goes for $b.

Avoid magic numbers
This is not very easy to understand:
      if ($i == $a){
        echo &quot;&lt;/li&gt;&lt;li&gt;&quot;;

        $a = $i + 2 + $b;
        $b++;
      }

Why + 2? This really could use some clarification. I suggest to make 2 a constant with a meaningful name earlier in your code.