Why is my variable not iterating in this foreach loop?
<p>I am trying to make a div ID have a unique name by using a variable to iterate through the number of times it gets looped.  For some reason my $k variable doesn't seem to be advancing.  Here is the code:</p>

<pre><code>&lt;?php foreach($files as $media)
                { 
                    $k = 0;
                    ?&gt;
                    &lt;h3&gt;&lt;?php echo $output[$j] ?&gt;&lt;/h3&gt;
                    &lt;div id='mediaspace&lt;?php echo $k ?&gt;'&gt;This text will be replaced&lt;/div&gt;

                    &lt;script type='text/javascript'&gt;
                      ...
                      so.write('mediaspace&lt;?php echo $k ?&gt;');
                    &lt;/script&gt;
                &lt;?php 
                $k = $k+1;
                } ?&gt;
</code></pre>

<p>My HTML output just gives me a 0 for $k every time the loop is run:</p>

<pre><code>&lt;div id='mediaspace0'&gt;This text will be replaced&lt;/div&gt;


                    &lt;script type='text/javascript'&gt;
                     ...                  so.write('mediaspace0');
                    &lt;/script&gt;
                                        &lt;h3&gt;Rattletree Marimba Day&lt;/h3&gt;
                    &lt;div id='mediaspace0'&gt;This text will be replaced&lt;/div&gt;

                    &lt;script type='text/javascript'&gt;
                      ...                 so.write('mediaspace0');
                    &lt;/script&gt;
</code></pre>

<p>Any help greatly appreciated!</p>
