I've seen some of the questions about the passing PHP arrays to an external JavaScript file, but I can't understand it. I know how to pass PHP arrays to internal JavaScript files but not how to pass them to external JavaScript files.
Coding
<?php
$a = array("Apple","Orange","Grape");
?>
<script type="text/javascript">
var jArray= <?php echo json_encode($a); ?>;
for(var i=0;i<3;i++){
alert(jArray[i]);
}
use this code, JS File (test.js)
PHP File (test.php)