JavaScript Array php values

2

In my database I have

id , coluna1, coluna2

1  , 38.951399 ,  -76.958463

2 , 38.942855,   -76.959149

I'm using php

I need to transform this information into an array in JavaScript with the following structure

 new Array([38.951399, -76.958463], [38.942855, -76.959149]);

    
asked by anonymous 31.07.2014 / 14:46

2 answers

2

Mount array in php first, then output with:

echo json_encode($minhaArray);

The result will be:

[[38.951399, -76.958463], [38.942855, -76.959149]]
    
31.07.2014 / 14:51
3

Use json_encode() :

<?php

$array = array(
    '1' => array('38.951399' ,  '-76.958463'),
    '2' => array('38.951399' ,  '-76.958463'),
);

$var = json_encode($array);

Already in view , you print like this:

<script> var javascriptArray = <?php echo $var ?> </script>
    
31.07.2014 / 14:52