How can a PHP script be modified to display a large image next to a thumbnail when clicked?

To display a large image next to a thumbnail when clicked in a PHP script, you can use JavaScript to handle the click event and dynamically change the source of the large image element. You can create a function that updates the src attribute of the large image element with the clicked thumbnail's source. This way, when a thumbnail is clicked, the corresponding large image will be displayed.

<?php
// HTML code for thumbnails and large image
echo '<img src="thumbnail1.jpg" class="thumbnail" onclick="showLargeImage(this.src)">';
echo '<img src="thumbnail2.jpg" class="thumbnail" onclick="showLargeImage(this.src)">';
echo '<img src="thumbnail3.jpg" class="thumbnail" onclick="showLargeImage(this.src)">';
echo '<img src="thumbnail4.jpg" class="thumbnail" onclick="showLargeImage(this.src)">';
echo '<img id="largeImage" src="" style="display: none;">';

// JavaScript function to show large image
echo '<script>';
echo 'function showLargeImage(src) {';
echo '  document.getElementById("largeImage").src = src;';
echo '  document.getElementById("largeImage").style.display = "block";';
echo '}';
echo '</script>';
?>