How can PHP be integrated with JavaScript to dynamically change content on a webpage without reloading the entire page?

To dynamically change content on a webpage without reloading the entire page, you can use PHP to fetch data from a server and then use JavaScript to update the content on the client-side. One common approach is to make an AJAX request to a PHP script that returns the updated content, which can then be rendered on the webpage without a full reload.

<?php
// PHP script to fetch data and return it as JSON
$data = [
    'message' => 'Hello, World!'
];

header('Content-Type: application/json');
echo json_encode($data);
?>