Any way to break if statement in PHP?

前端 未结 20 2014
無奈伤痛
無奈伤痛 2020-12-02 05:05

Is there any command in PHP to stop executing the current or parent if statement, same as break or break(1) for switch/

20条回答
  •  离开以前
    2020-12-02 05:18

    i have a simple solution without lot of changes. the initial statement is

    I want to break the if statement above and stop executing echo "yes"; or such codes which are no longer necessary to be executed, there may be or may not be an additional condition, is there way to do this?

    so, it seem simple. try code like this.

    $a="test";
    if("test"==$a)
    {
      if (1==0){
          echo "yes"; // this line while never be executed. 
          // and can be reexecuted simply by changing if (1==0) to if (1==1) 
      }
    }
    echo "finish";
    

    if you want to try without this code, it's simple. and you can back when you want. another solution is comment blocks. or simply thinking and try in another separated code and copy paste only the result in your final code. and if a code is no longer nescessary, in your case, the result can be

    $a="test";
    echo "finish";
    

    with this code, the original statement is completely respected.. :) and more readable!

提交回复
热议问题