How to assign a variable to the JS variable value to PHP?

Good day!

How to pass PHP variable value in javascript?
July 9th 19 at 11:28
4 answers
July 9th 19 at 11:30
<script ...>
 var v = "<?=$var; ?>";
But if $var is a number or an array? - Violet_Wiso commented on July 9th 19 at 11:33
: Then see other answers about json, or print the array cycle. - Daphne_Roob commented on July 9th 19 at 11:36
July 9th 19 at 11:32
<script type="text/javascript">
var variable = <?=json_encode($variable); ?>
July 9th 19 at 11:34
<script type="application/json" id="json"><?=json_encode($variable)?></script>
the <script>
 var json = JSON.parse($('#json').text());
July 9th 19 at 11:36
Describe what you intend to do. For the solution above may be incorrect.

Find more questions by tags PHP