break out of if and foreach

后端 未结 4 1897
鱼传尺愫
鱼传尺愫 2020-11-30 17:43

I have a foreach loop and an if statement. If a match is found i need to ultimately break out of the foreach.

foreach ($equipxml as $equip) {

    $current_de         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 18:32

    foreach($equipxml as $equip) {
        $current_device = $equip->xpath("name");
        if ( $current_device[0] == $device ) {
            // found a match in the file            
            $nodeid = $equip->id;
            break;
        }
    }
    

    Simply use break. That will do it.

提交回复
热议问题