<script type="text/javascript">
var phpVars = {
<?php
foreach ($phpToJsVars as $key => $value) {
echo ' ' . $key . ': ' . '"' . $value . '",' . "
";
}
?>
};
</script>
<script type="text/javascript" src="YourFunctions.js"></script>
<script type="text/javascript">
functionOne(<?php echo implode(', ', $arrayWithVars); ?>);
functionTwo(<?php echo $moreVars; ?>, <?php echo $evenMoreVars; ?>);
</script>
phpVars["value1"]
phpVars["value2"]
<?php
$phpToJsVars = [
'value1' => 'foo1',
'value2' => 'foo2'
];
?>
AddType application/x-httpd-php .js
AddHandler x-httpd-php5 .js
<FilesMatch ".(js|php)$">
SetHandler application/x-httpd-php
</FilesMatch>