How can PHP code be executed from JavaScript?

To execute PHP code from JavaScript, you can make an AJAX request to a PHP file on the server and then process the response in JavaScript. This allows you to run PHP code on the server and receive the output in your JavaScript code. ```javascript // AJAX request to execute PHP code var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { // Process PHP output in JavaScript console.log(this.responseText); } }; xhttp.open("GET", "example.php", true); xhttp.send(); ``` In the example above, the JavaScript code sends a GET request to a PHP file named "example.php" on the server. The PHP code in "example.php" will be executed on the server, and the response will be logged to the console in JavaScript.