Rss Feed
  1. Assigning php array to javascript

    Thursday, 21 March 2013

    <?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

  2. 0 comments:

    Post a Comment