How can PHP be integrated with Google Maps to display geolocation data?

To integrate PHP with Google Maps to display geolocation data, you can use the Google Maps JavaScript API to create a map on a web page and then use PHP to fetch geolocation data from a database or API and display it on the map.

<!DOCTYPE html>
<html>
<head>
    <title>Google Maps API with PHP</title>
    <style>
        #map {
            height: 400px;
            width: 100%;
        }
    </style>
</head>
<body>
    <div id="map"></div>
    <script>
        function initMap() {
            var map = new google.maps.Map(document.getElementById('map'), {
                zoom: 10,
                center: {lat: -34.397, lng: 150.644}
            });

            <?php
                // Fetch geolocation data using PHP and loop through the data to add markers to the map
                $locations = array(/* Fetch geolocation data from database or API */);
                foreach($locations as $location) {
                    echo "var marker = new google.maps.Marker({position: {lat: " . $location['lat'] . ", lng: " . $location['lng'] . "}, map: map});";
                }
            ?>
        }
    </script>
    <script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"></script>
</body>
</html>