What's wrong with this code? Trying to output a number pattern
<p>There is a pattern that goes like this:</p>

<pre><code>1
11
21
1211
111221
...
</code></pre>

<p>I'm trying to write PHP code to output this, but my output is:</p>

<pre><code>1
11
21
12
11
21
12
...
</code></pre>

<p>Here's the code:</p>

<pre><code>&lt;?
$sequence = "1";

for ($i = 0; $i &lt; 99; $i++) {

    echo "{$sequence}&lt;br /&gt;";

    $n = 0;
    $x = 0;
    $z = 1;

    $newsequence = "";

    for ($y = count($sequence); $y &gt; 0; $y--) {
        while ($sequence[$n] == $sequence[$n + 1]) {
            $z++;
            $n++;
        }

        $newsequence .= "{$z}{$sequence[$n]}";
    } 

    $sequence = $newsequence;
}

?&gt;
</code></pre>

<p>What am I missing?</p>
