Using PHP within Javascript functions
<p>What is the best way to handle mixing PHP into Javascript? Should it not be done? Should it be done in a certain way? I am working on a project and I found the following javascript function: </p>

<pre><code>function getStuff() {
                &lt;?php
                $stuff = "0:Select";
                foreach ($this-&gt;stuff as $k =&gt; $v){
                    $stuff = $stuff . ";" . $v['stuff_id'] . ":" . $v['stuff_name'];
                }
                ?&gt;

                return "&lt;?= $stuff ?&gt;";
            }
</code></pre>

<p>Assuming I need the data that the PHP is providing what is the ideal way to get it? This doesn't seem like it to me but the person that wrote this is my boss so I want to ask before trying to change it.</p>

<p>FYI, this JS is used in a view script and the data for <code>$this-&gt;stuff</code> is passed in from the controller that uses it.</p>
