, JS, PHP json_encode.
For example, if you have an array in PHP
<?php
$cow=array('bat'=>false,'fob'=>'widget');
What do you want in js then you could
<script>
var cow=<?php echo json_encode($cow);?>;
// prints {"bat":false,"fob":"widget"}
console.log(cow.fob);//'widget' of course
json_encode also takes care of quoting strings. Of course, not all PHP values are json_encodable - objects with methods cannot be expressed as javascript values, but that doesn't seem like you're worried about this.
source
share