Break does not work in foreach

2

I have a foreach inside another foreach that will rotate by several values of a specific object. But I need to stop both foreach's when it goes into if, but the break command does not work for some reason, it just keeps running both foreach's. The code looks something like this:

foreach($conteudo["data"] as $oddss) {

    foreach($oddss["types"]["data"] as $oddss2) {
        if($oddss2["type"] == "1x2") {

            $bookmarker = $oddss["bookmaker_id"];

            foreach($oddss2["odds"]["data"] as $oli) {

                switch($oli["label"]) {
                    case 1:
                        $cotCasa = $oli["value"];
                        break;
                    case 2:
                        $cotFora = $oli["value"];
                        break;
                    case "X":
                        $cotEmp = $oli["value"];
                }

            }
            break;
        }
    }

}
    
asked by anonymous 16.03.2017 / 15:13

1 answer

2

break is leaving switch and not foreach , change it to if / elseif that does not need break to exit and then break will exit foreach . Or use break 2 to do two outputs, one of switch and another of foreach .

    
16.03.2017 / 15:15