0

我正在尝试转换该 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 数组,但我不知道如何。我怎样才能做到这一点?

4

2 回答 2

1

您需要将其转换为 JSON。看看这个函数http://php.net/manual/en/function.json-encode.php

于 2013-03-21T21:02:01.140 回答
0

听说过JSON吗?

<?

$jsarray = json_encode($phpArray);

?>

<script>

var myArray = <? echo $jsarray; ?>;

</script>

也许这会有所帮助: http: //php.net/manual/en/ref.json.php

于 2013-03-21T21:03:49.070 回答