I have an array($coords) in php which contains some coordinates.
print_r($coords)
gives
Array ( [0] => 80.23338342111089 ,26.52748985468579 [1] => 80.21915925983853 ,26.51065783417543 [2] => 80.23036859334592 ,26.49785585262899 [3] => 80.24667293123426 ,26.51075259323626 [4] => 80.23338342111089 ,26.52748985468579 )
Then I used $string = implode(",",$coords);
print_r($string);
It gave me
80.23338342111089 ,26.52748985468579,80.21915925983853 ,26.51065783417543,80.23036859334592 ,26.49785585262899,80.24667293123426 ,26.51075259323626,80.23338342111089 ,26.52748985468579
I passed this to Javascript like this-
var Coordinates = [];
Coordinates.push(<?php echo ($string); ?>);
now I want to stringify this so I used-
var JSON_Coordinates = JSON.stringify(Coordinates);
Now the value of JSON_Coordinates is-
[80.23338342111089 ,26.52748985468579,80.21915925983853 ,26.51065783417543,80.23036859334592 ,26.49785585262899,80.24667293123426 ,26.51075259323626,80.23338342111089 ,26.52748985468579]
But it should be-
[[80.23338342111089 ,26.52748985468579],[80.21915925983853 ,26.51065783417543],[80.23036859334592 ,26.49785585262899],[80.24667293123426 ,26.51075259323626],[80.23338342111089 ,26.52748985468579]]
Someone please tell me where am i wrong?
Thanks.
$coordsis more a string than an array.