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.
foreach ($a as $b) {
include("javascript.php");
}
javascript.php contains codes like this:
<script>
$(".<?php echo $somevariable?>").something;
</script>
My question is: What is the most efficient (if any) way to load javascript that contains PHP variables?
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.
Thanks for your insight.