How can PHP scripts be integrated with AJAX to achieve automatic updates without reloading the entire page?

To achieve automatic updates without reloading the entire page using AJAX and PHP, you can create a PHP script that returns the updated data in response to an AJAX request. This script can be called periodically using JavaScript's setInterval function to fetch the updated data and update the page dynamically.

<?php
// PHP script to fetch and return updated data
// This script can be called via AJAX to get new data

// Code to fetch updated data goes here
$updatedData = "New data fetched from the server";

// Return the updated data as JSON
echo json_encode($updatedData);
?>