Передача массивов PHP в JavaScript
var ar = <?php echo '["' . implode('", "', $ar) . '"]' ?>;
Motionless Moose
var ar = <?php echo '["' . implode('", "', $ar) . '"]' ?>;
<?php
// php array
$fruits = array('apple', 'orange', 'mango', 'banana', 'strawberry');
?>
<script type="text/javascript">
// use php implode function to build string for JavaScript array literal
var fruits = <?php echo '["' . implode('", "', $fruits) . '"]' ?>;
// ["apple", "orange", "mango", "banana", "strawberry"]
</script>