All of PHP's applications are performed through a Web server (such as IIS or Apache) and a PHP engine program that explains how the process works:
(1) When the user enters the file name of the PHP page to be accessed in the browser address, then enter will trigger the PHP request and transfer the request to a PHP-enabled Web server.
(2) The Web server accepts this request and makes a decision based on the suffix if it is a PHP request, the Web server pulls the PHP application that the user wants to access from the hard disk or memory and sends it to the PHP engine program.
(3) The PHP engine program (typically PHP.exe) will scan the Web server's files from start to finish, read from the background according to the commands, process the data, and dynamically generate the corresponding HTML page.
(4) The PHP engine returns the generated HTML page to the Web server. The Web server then returns the HTML page to the client browser.
So if PHP is to pass a value to the HTML JS script, how to do? You can define the variables before you need them, as in the following example: