use php in javascript file code example
Example 1: how to write php in script file
<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>
Example 2: how to write php in script file
<?php
$phpToJsVars = [
'value1' => 'foo1',
'value2' => 'foo2'
];
?>