Convert php array to javascript array

by Subramanian 2013-04-06 11:18:54

<font size=4>Convert php array to javascript array</font>

1. Create php array

<?php
$arrPhp=array("1","2","3","4","5');
?>


2. Create javascript array

<script>
var arrJava=new Array();
</script>


3. Now assign php array value to javascript array value

<script>
<?php
for($i=0;$i<count($arrPhp);$i++)
echo "arrJava[".$i."]=".$arrPhp[$i].";";
?>

alert(arrJava);
</script>


652
like
0
dislike
0
mail
flag

You must LOGIN to add comments