What are the benefits of using the data-lightbox attribute in HTML when working with images in PHP?

When working with images in PHP, using the data-lightbox attribute in HTML can provide a simple and elegant solution for creating image galleries with lightbox functionality. This attribute allows you to easily group images together and display them in a modal window when clicked, providing a user-friendly way to view images without navigating away from the current page.

<?php
// Loop through an array of image URLs and output them with the data-lightbox attribute
$images = [
    'image1.jpg',
    'image2.jpg',
    'image3.jpg'
];

foreach ($images as $image) {
    echo '<a href="' . $image . '" data-lightbox="image-gallery"><img src="' . $image . '" alt="Image"></a>';
}
?>