Elemente maximal pro Zeile dann Umbruch

EuroCent

Klappstuhl 2.0
Guten Morgen zusammen,

ich sitze vor einem kleinem Problem...
Und zwar möchte Ich die Button-Groups so verteilen dass sie ab einer bestimmten Anzahl, in die nächste Zeile rutschen, als neues Button-Group-Modell.
Aber irgendwie hab Ich glaub ich eine Blockade und komme nicht drauf :/

Theoretisch geht es mit einem Count den Ich hochzähle und dann entsprechend per Modular (%) auf 0 runter breche und oder so.
Beispielsweise:
PHP:
<?php
if($count % 5 == 0) {}
?>

Aktuell hab Ich es wie folgt:
PHP:
            <tr>
                <td>
                    <div class="col-12">

                        <div class="btn-group btn-group-sm mb-3" data-toggle="buttons" role="group">

<?php
$r_array = explode(',', $zeile['grids']);
foreach ($data as $r_single) {

    $checked = $active = "";
    if (in_array($r_single['r_id'], $r_array)) {

        $checked = "checked";
        $active = "active";
    }
    ?>
                                <label class="btn btn-secondary filter-label <?php echo $active; ?>">
                                    <input name="added_rights" class="sf" type="checkbox" style="display: none;" data-mid="<?php echo $zm['modul_id']; ?>"data-rid="<?php echo $r_single['r_id']; ?>" <?php echo $checked; ?>/><?php echo $r_single['r_bez']; ?>
                                    <span class="fa fa-check"></span>
                                </label>
                                <?php
                            }
                            ?>

                        </div>
                    </div>
                </td>
            </tr>

Kann mir hierbei einer einen Denk anstoß geben wo Ich die Abfrage einbauen muss?
Oder wie der Aufbau dann sein müsst? :)

Vielen lieben Dank :)
 
Lösung
Bisschen chaotisch formatiert. Dann lass uns mal Klammern zählen un herauszufinden was wo beginnt und endet.

PHP:
<?php
    $r_array = explode(',', $zeile['grids']);
    //Zähler initialisieren
    $i = 0;
    foreach ($data as $r_single) {
        $checked = $active = "";
        if (in_array($r_single['r_id'], $r_array)) {

            $checked = "checked";
            $active = "active";
        }
        //Zeilenumbruch einfügen
        if(0 = $i++ % 5) echo '<br />'
?>
                                <label class="btn btn-secondary filter-label <?php echo $active; ?>">
                                    <input name="added_rights" class="sf" type="checkbox" style="display: none;" data-mid="<?php echo $zm['modul_id']...
Bisschen chaotisch formatiert. Dann lass uns mal Klammern zählen un herauszufinden was wo beginnt und endet.

PHP:
<?php
    $r_array = explode(',', $zeile['grids']);
    //Zähler initialisieren
    $i = 0;
    foreach ($data as $r_single) {
        $checked = $active = "";
        if (in_array($r_single['r_id'], $r_array)) {

            $checked = "checked";
            $active = "active";
        }
        //Zeilenumbruch einfügen
        if(0 = $i++ % 5) echo '<br />'
?>
                                <label class="btn btn-secondary filter-label <?php echo $active; ?>">
                                    <input name="added_rights" class="sf" type="checkbox" style="display: none;" data-mid="<?php echo $zm['modul_id']; ?>"data-rid="<?php echo $r_single['r_id']; ?>" <?php echo $checked; ?>/><?php echo $r_single['r_bez']; ?>
                                    <span class="fa fa-check"></span>
                                </label>
<?php
    }
?>
 
Lösung
Danke @Yaslaw
Hatte einfach nur eine Blockade :D

Hab es dann wie folgt lösen können:
PHP:
                            <?php
                            $r_array = explode(',', $zeile['grids']);
                            $counter = 0;
                            foreach ($data as $r_single) {
                                $test++;
                                $checked = $active = "";
                                if (in_array($r_single['r_id'], $r_array)) {

                                    $checked = "checked";
                                    $active = "active";
                                }
                                ?>
                                <label class="btn btn-secondary filter-label <?php echo $active; ?>">
                                    <input name="added_rights" class="sf" type="checkbox" style="display: none;" data-mid="<?php echo $zm['modul_id']; ?>"data-rid="<?php echo $r_single['r_id']; ?>" <?php echo $checked; ?>/><?php echo $r_single['r_bez']; ?>
                                    <span class="fa fa-check"></span>
                                    <span class="fa fa-square"></span>
                                </label>
                                <?php
                                if ($counter % 6 === 0) {
                                    echo "</div>";
                                    echo '<div class="btn-group btn-group-sm mb-3" data-toggle="buttons" role="group">';
                                }
                            }
                            ?>

Hatte es vorher nicht korrekt Formatiert daher sah es etwas unübersichtlicher aus :)

Jetzt hab Ich es so wie Ich es wollte :)

Dennoch vielen lieben Dank :)
 
Zurück