php - Implement for foreach loop in javascript on Multi-dimensional arrays Issue -


i'm trying implement foreach php loop in javascript
php code multidimensional array is:

echo json_encode($jsonpoly); foreach( $jsonpoly $route => $cordarray) {      echo $route.': ';     echo implode(',',$cordarray);     } 

my multidimensional array output is:

{"route1":["22.2740,70.8275"], "route2":["22.2739,70.8276"], "route3":["22.2739,70.8276"], "route4":["22.2739,70.8276"], "route5":["22.2731,70.8303","22.2879,70.8264","22.3027,70.8125","22.3067,70.8137","22.2973,70.8158","22.2936,70.8201","22.2848,70.8157","22.2815,70.8161","22.2803,70.8245","22.2739,70.8276"],"route6":["22.2739,70.8277"]}<br> 

this attempt print javascript

var jsonpoly=new array();                                jsonpoly = '"<?php echo json_encode($jsonpoly); ?>"';  for(var route in jsonpoly){     // printing each "route" } 


there wrong in loop? or in multidimensional array?
advice.
thanks!

to values in javascript can use output of json_encode directly:

jsonpoly = <?php echo json_encode($jsonpoly); ?>; 

this gets you:

val = {"foo":"bar"}; 

vs:

val = '"{"foo":"bar"}"'; // need json.parse 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -