简体   繁体   中英

PHP- foreach loop array breaks and does not loop the next one

I am working on a project that has milestones and milestonefases(parts of milestone). I want to have milestones 1 time and I want the fases below of milestones. How can I get the milestone 1 time? I think it is someting about foreachloop and break right?

My code:

        <?php
        foreach ($stones_fases as $stone_id => $stone_value){
            foreach($stone_value as $fase_id => $value){?>
                <tr id="<?= $stone_id ?>" class="milestone<?= $stone_id ?>">
                    <td><?= $stone_id ?></td>
                    <td><b><a href="javascript:keuzeGebruiker(milestone<?= $stone_id ?>,<?= $stone_id ?>);"> <?= $value['milestone_titel'] ?></a></b></td>
                    <td><?= $value['milestone_client'] ?></td>
                </tr>
                <?php break; ?>

                <tr id="<?= $fase_id ?>" class="milestone<?= $stone_id ?>fase fase">
                    <td><?= $fase_id ?></td>
                    <td><?= $value['milestonefase_titel'] ?></td>
                    <td></td>
                </tr>

                <?php if (in_array($stone_id, $antwoordCookieMilestones)) { // If in array is the milestone id, then show that milestone.
                    echo '<style>.milestone' . $stone_id . 'fase{display: table-row!important;}</style>';
                }
            }
        }
        ?>

I used that break to have my milestones 1 time but after that. I do not get milestonefases

This is my array $stones_fases :

Array
(
    [6] => Array
        (
            [10] => Array
                (
                    [milestone_id] => 6
                    [milestone_titel] => Registranten systeem portaal
                    [milestone_client] => stackoverflow
                    [milestone_verkocht_id] => 99
                    [milestone_omschrijving] => Door middel van het plaatsen 
                    [milestonefase_id] => 10
                    [milestonefase_titel] => Functiebeheer CMS maken
                    [milestonefase_milestone_id] => 6
                    [milestonefase_omschrijving] => Om visitors te kunnen 
                    [milestonefase_verwerkt] => 1
                )

Are u $stone_id ? Do you know what ur doing in a

foreach { foreach { //part1 result, break; //part2 result } }

With this break u can never reach the code after that. This structure is bad. Maybe u can do things like

if($stone_id == 1) { //part1 result }

To limit ur milestone... The break says. Cancel the inner foreach. Interate the outer foreach. And in next queue there is the same. u only can get the first part if you break always without condition

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM