0

I'm trying to convert that PHP array :

    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
        )

to a javascript array, but I don't know how. How can I do that?

2
  • 2
    echo "var my_js_array=" . json_encode( $my_php_array ) . ";"; Commented Mar 21, 2013 at 21:03
  • You could have it print out and target it's container to convert to array. I don't know much about JSON but that's one way. Commented Mar 21, 2013 at 21:03

2 Answers 2

1

You need to translate this into JSON. Have a look at this function http://php.net/manual/en/function.json-encode.php

0

Ever heard of JSON?

<?

$jsarray = json_encode($phpArray);

?>

<script>

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

</script>

And perhaps this helps: http://php.net/manual/en/ref.json.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.