PHP is a server-side scripting language. This means that the PHP is executed on the server and the output is sent to the client's browser. The web browser cannot see the PHP nor can it execute it, it can only see the results or output. JavaScript is a client-side scripting language. This means that the server does not execute JavaScript, only the web browser does.
JavaScript cannot directly interact with PHP because the PHP will always be executed first by the server and then sent to the client's browser. JavaScript can only pass information to PHP.
Since PHP is always executed before JavaScript then the JavaScript variables must be passed through a form or the URL. Those are the only two options. Granted, you can use AJAX, but that still uses GET or POST. So, to retrieve these JavaScript variables, on the server-side, you will have to use $_GET or $_POST.
PHP variables can be passed to JavaScript. Anything you echo or print to the browser becomes part of the direct source code. Simply echo the JavaScript you want.
JavaScript cannot directly interact with PHP because the PHP will always be executed first by the server and then sent to the client's browser. JavaScript can only pass information to PHP.
Since PHP is always executed before JavaScript then the JavaScript variables must be passed through a form or the URL. Those are the only two options. Granted, you can use AJAX, but that still uses GET or POST. So, to retrieve these JavaScript variables, on the server-side, you will have to use $_GET or $_POST.
PHP variables can be passed to JavaScript. Anything you echo or print to the browser becomes part of the direct source code. Simply echo the JavaScript you want.
JavaScript can not call a PHP function but PHP can call a JavaScript function. Just output a call to the function. You may also pass parameters this way.