What are the advantages and disadvantages of using a variable loop header and footer in PHP templates?

Using a variable loop header and footer in PHP templates allows for dynamic content to be displayed based on the data being looped through. This can help reduce redundancy in code and make the template more flexible. However, it can also make the template harder to read and maintain if not implemented properly.

<?php
// Define the loop header and footer as variables
$loopHeader = '<ul>';
$loopFooter = '</ul>';

// Loop through data and display content with header and footer
foreach ($data as $item) {
    echo $loopHeader;
    echo '<li>' . $item . '</li>';
    echo $loopFooter;
}
?>