Your Ad Here

Tuesday, October 4, 2011

Convert PHP array to Javascript array

A very basic tutorial. For the beginners who want to pass array values from PHP to Javascript for them to be accessible in the client side JS as an array. It’s really easy to pass PHP array to Javascript.
The below code passes a string array in PHP to Javascript.




<?php

$arr = array("a","b","c");

?>

<script>

var jsArray = ["<?php echo join("\", \"", $arr); ?>"];

alert(jsArray);

</script>

No comments:

Post a Comment