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;
1

1 Answer 1

3

It looks be next:

$dom.= 'var loop="' . $loop_from_php . '";';
$dom.= 'var array=' . json_encode($winner_ids) . ';';
echo $dom;
Sign up to request clarification or add additional context in comments.

1 Comment

The value of array shouldn't be quoted

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.