Why does 'Cannot break/continue 1 level' comes in PHP?

后端 未结 3 1187
南旧
南旧 2021-02-18 19:55

I am getting sometimes this error on production at:

if( true == $objWebsite ) {
    $arrobjProperties = (array) $objWebsite->fetchProperties( );
    if( false         


        
3条回答
  •  悲哀的现实
    2021-02-18 20:23

    If you want to still break from if, you can use while(true)

    Ex.

    $count = 0;
    if($a==$b){
        while(true){
            if($b==$c){
                $count = $count + 3;
                break;  // By this break you will be going out of while loop and execute remaining code of $count++.
            }
            $count = $count + 5;  //
            break;  
        }
        $count++;
    }
    

    Also you can use switch and default.

    $count = 0;
    if($a==$b){
        switch(true){
          default:  
             if($b==$c){
                $count = $count + 3;
                break;  // By this break you will be going out of switch and execute remaining code of $count++.  
            }
            $count = $count + 5;  //
        }
        $count++;
    }
    

提交回复
热议问题