<?php
$phpArray = array("hi" => "hello"); ?> <script>
var jsArray = <?php echo json_encode($phpArray); ?>;
alert(jsArray.hi);
</script>
// use jsArray.hi or jsArray[hi]
Refer: http://sandbox.phpcode.eu/g/9e705
Refresh it to get result
$phpArray = array("hi" => "hello"); ?> <script>
var jsArray = <?php echo json_encode($phpArray); ?>;
alert(jsArray.hi);
</script>
// use jsArray.hi or jsArray[hi]
Refer: http://sandbox.phpcode.eu/g/9e705
Refresh it to get result
0 comments:
Post a Comment