What is the purpose of a for-loop in PHP when creating a klappentext?

The purpose of a for-loop in PHP when creating a klappentext (accordion text) is to iterate over a set of data or elements and generate the necessary HTML structure for the accordion. This allows for dynamically creating multiple accordion sections based on the provided data.

<?php
// Sample data for accordion sections
$accordionData = array(
    "Section 1" => "Content for section 1",
    "Section 2" => "Content for section 2",
    "Section 3" => "Content for section 3"
);

// Output accordion sections using a for-loop
foreach ($accordionData as $title => $content) {
    echo '<button class="accordion">' . $title . '</button>';
    echo '<div class="panel">' . $content . '</div>';
}
?>