Convert PHP Array into Javascript Array

by Sasikumar 2014-05-27 18:44:23

To convert PHP array into Javascript array use the following code,
<?php $phpArray = array( 0 => "hiox.com", 1 => "hiox.org", 2 => "hscripts.com",  3 => "hibihi.com"); ?>
<script>
var jsArray = new Array();
<?php foreach( $phpArray as $key=>$value ) { ?>
    jsArray['<?=$key;?>'] = '<?=$value;?>';
<?php } ?>
alert(jsArray);
</script>
"jsArray" will contain the same array as "phpArray".
627
like
0
dislike
0
mail
flag

You must LOGIN to add comments