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

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -