tags:

views:

60

answers:

2
+1  Q: 

from php to jquery

hi,

i have array in php, and i need work with this array in jQuery. What best way send array( or variable ) from php to jQuery? Thanks

+7  A: 

json_encode() (PHP >= 5.2) is arguably the easiest way.

$array_js = json_encode($array);

echo "<script type='text/javascript'> my_array = ".$array_js."; </script>";
Pekka
If you're (PHP < 5.2), I've had success with the jsonwrapper script. http://www.boutell.com/scripts/jsonwrapper.html
Aaron W.
+1  A: 

If you don’t have to dynamically load it, try something like this:

<script>
var the_array = <?php echo json_encode($array); ?>
</script>
Scytale