assign php array to javascript code example

Example 1: php array to js

var arrNums = json_encode(<?php echo $arrNums; ?>);

Example 2: assign php array into javascript

<script type="text/javascript">

	$(document).ready(function() {
      FACILITY_BOOKING.lst_festival_day = new Array();
      <?php foreach($festival_day as $key => $val) { ?>
        FACILITY_BOOKING.lst_festival_day.push('<?php echo $val; ?>');
      <?php } ?>
    });
</script>

Example 3: copy php array to javascript

var js_array = [<?php echo '"'.implode('","', $php_array).'"' ?>];

Tags:

Php Example