Any way to break if statement in PHP?

前端 未结 20 2097
無奈伤痛
無奈伤痛 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:33

    The simple solution is to comment it out.

    $a="test";
    if("test"==$a)
    {
    
      //echo "yes"; //no longer needed - 7/7/2014 - updateded bla bla to do foo
    }
    

    The added benefit is your not changing your original code and you can date it, initial it and put a reason why.

    Why the down vote, according to the OP request I think this is a perfectly valid solution.

    "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?"

    In fact someone could look at some of the other solutions, a year latter and wonder what is going on there. As per my suggestion, one could leave good documentation for future reference, which is always good practice.

提交回复
热议问题