how to put javascript variable in php echo [closed]

I want to add JavaScript variable to php echo

arr[i]='<?php echo $winner[javascript variable]; ?>';

Thanks


Solution 1:

You can't.

  1. PHP runs on the server and outputs some text.
  2. The text is sent to the browser
  3. The browser interprets the text as HTML / JavaScript / etc

The PHP has finished running by the time the JavaScript is executed.

If you want to pass data back you need to make a new HTTP request and run a PHP script from scratch.