In the provided PHP code snippet, what improvements can be made to optimize the generation of image displays and CSS classes?

The issue with the provided PHP code snippet is that it generates image displays and CSS classes in a repetitive and inefficient manner, leading to redundant code and decreased performance. To optimize this, we can create a function to generate the image displays and CSS classes dynamically based on input parameters, reducing redundancy and improving code readability.

<?php
function generateImageDisplay($imagePath, $altText, $cssClass) {
    echo '<img src="' . $imagePath . '" alt="' . $altText . '" class="' . $cssClass . '">';
}

// Example of generating image displays using the function
generateImageDisplay('image1.jpg', 'Image 1', 'image-class');
generateImageDisplay('image2.jpg', 'Image 2', 'image-class');
generateImageDisplay('image3.jpg', 'Image 3', 'image-class');
?>