Value of php in javascript?

0

The idea is that this is not working when I add the value of the php variable directly in the javascript, for example -3,3462, -60,6790 it works, do you know what it could be?

<?php 
$variavel = "-3,3462, -60,6790";
?>

<script> 

var testMarker = L.marker([<?php $variavel;?>],{icon: orangeIcon});  

</script>
    
asked by anonymous 13.04.2017 / 10:41

2 answers

4

Change: <?php $variavel;?>

To: <?php echo $variavel;?>

<?php 
$variavel = "-3,3462, -60,6790";
?>

<script> 

var testMarker = L.marker([<?php echo $variavel;?>],{icon: orangeIcon});  

</script>
    
13.04.2017 / 10:52
0

If your variable is an array, do so:

<?php 
  $variavel = ["-3,3462", "-60,6790"];
?>

<script> 

var testMarker = L.marker([<?php echo $variavel[0];?>,<?php echo $variavel[1];?>],{icon: orangeIcon});  
</script>
    
13.04.2017 / 13:20