What is the most efficient way to include many javascript functions (with PHP in them) in a PHP page?
<p>In one of my sites, I need to use PHP 'foreach' to keep including some Javascript code. In this code contains PHP $variables that change within the foreach loop. </p>

<pre><code>foreach ($a as $b) {
   include("javascript.php");  
}
</code></pre>

<p>javascript.php  contains codes like this:          </p>

<pre><code>&lt;script&gt;
   $(".&lt;?php echo $somevariable?&gt;").something;
&lt;/script&gt;
</code></pre>

<p>My question is: What is the most efficient (if any) way to load javascript that contains PHP variables?</p>

<p>I keep reading that it's better to call large javascript codes in a .js script rather than writing it on the page, But apparently .js files can not have PHP.</p>

<p>Thanks for your insight.</p>
