我正在尝试转换该PHP数组:
Array
(
[1] =>
Array
(
[ID] => 6927
[Town] => Paris
[latitude] => 48.867521
[longitude] => 2.3317145
)
[2] => Array
(
[ID] => 6928
[Town] => Paris
[latitude] => 48.8615398
[longitude] => 2.3496911
)
[3] => Array
(
[ID] => 6929
[Town] => Paris
[latitude] => 48.8675335
[longitude] => 2.3292922
)
[4] => Array
(
[ID] => 6930
[Town] => Paris
[latitude] => 48.8686698
[longitude] => 2.3413497
)
到一个javascript数组,但我不知道如何。 我怎么能这样做?
答案 0 :(得分:1)
您需要将其转换为JSON。 看看这个函数http://php.net/manual/en/function.json-encode.php
答案 1 :(得分:0)
有没有听说过JSON?
<?
$jsarray = json_encode($phpArray);
?>
<script>
var myArray = <? echo $jsarray; ?>;
</script>