0

how can I place PHP variable in a JavaScript variable which is in a string .In below example I am showing few lines where I call PHP variable in script. I put all the html in $dom and then echo the page .

$dom.= 'var loop="<? echo $loop_from_php; ?>"';
$dom.= 'var array="<? echo json_encode($winner_ids); ?>"';
echo $dom;
Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
basiclearner
  • 49
  • 1
  • 8
  • 2
    Does this answer your question? [How do I pass variables and data from PHP to JavaScript?](https://stackoverflow.com/questions/23740548/how-do-i-pass-variables-and-data-from-php-to-javascript) – A. Khaled Jan 10 '21 at 13:43

1 Answers1

3

It looks be next:

$dom.= 'var loop="' . $loop_from_php . '";';
$dom.= 'var array=' . json_encode($winner_ids) . ';';
echo $dom;
Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39