PHP - having a hard time understading why a certain value is echoed. Can an assignment take place inside of if and executed in else?
<p>Hy to everyone ! 
Please excuse my ignorance, I'm so new to php.</p>

<p>I have a hard time understanding why a php code behaves in that way.
The code is working but I'm so clueless about why those values are echoed.</p>

<p>(The code has been simplified for explanation purposes but it would normally populate and format a table based on a custom number of columns)</p>

<p><strong><em></strong> QUESTION *</em>** 
   (see the code)</p>

<p>Why does the variable <code>$cell</code> echo (see: ?????? QUESTION ?????): 1 2 3 4 5 6 7  ?
I was expecting 0 1 2 3 4 5 6 // because I thought the starting point for it would be  $cell = 0, as assigned at the start. The only rational reason would be that it inherits its value from $cell +=$i (from the for loop), but when the case is $col=2 isn't the first statement skipped entirely and only the else statement executed? </p>

<pre><code>&lt;?php
for ($i=1; $i &lt;= 7 ; $i++)  {
    $cell = 0;
    echo "&lt;tr&gt;";

    for ($col=1; $col &lt;= 2; $col++) {
        echo "&lt;td&gt;" ;
        if ($col == 1) {
            echo $cell; // echoes: 0 0 0 0 0 0 0 ----&gt; because $cell = 0
            $cell +=$i;
            echo $cell; // echoes: 1 2 3 4 5 6 7  ----&gt; because of  $cell +=$i;
        } else {
            echo $cell ; // echoes: 1 2 3 4 5 6 7    ?????? QUESTION ?????
            $cell +=7;
            echo $cell; // echoes: 8 9 10 11 12 13 14
        }
        echo "&lt;/td&gt;";
    }
    echo "&lt;/tr&gt;";
}
?&gt;
</code></pre>

<p>Any help would be gratefully appreciated. </p>
