How to pass multidimensional array from PHP to Javascript? -


i trying array value json string, , work json_decode php.

<?php $jsoncontent=file_get_contents('http://megarkarsa.com/gpsjson.php'); $jsondecoded=json_decode($jsoncontent,true); foreach($jsonencoded['bms'] $p){ echo ' id: '.$p['id'].' tipe: '.$p['type'].' '; echo "<br>"; ?> 

the php code works, , give result of array json string. , javascript code

<script> var bmsdata = <?php echo $jsondecoded ?>; alert(bmsdata["1"].id); // check, want see id of row 1 </script> 

but nothing shown up. doing right far? or missing pass value php javascript? suggestion appreciated.

this 1 should work, lookup json @ http://megarkarsa.com/gpsjson.php ;)

<script> var bmsdata = <?php echo json_encode($jsondecoded); ?>; alert(bmsdata.bms["1"].id); // check, want see id of row 1 </script> 

you forgot 'bms' key ;)


Comments

Popular posts from this blog

xml - Extract substrings with XSLT -

math - "ELO Rating" and how does "TSR Rating" work? -

How can do a tuple comparison in coffeescript similar to that in python? -