Any way to break if statement in PHP?

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

    To completely stop the rest of the script from running you can just do

    exit; //In place of break. The rest of the code will not execute

    0 讨论(0)
  • 2020-12-02 05:35

    Answering to your question whether that is achievable or not, then yes that is achievable using "goto" operator of php.

    But ethically, its not a good practice to use "goto" and of there is any need to use goto then this means that code need to be reconstructed such that requirement of goto can be removed.

    According to the sample code you posted above, it can be clearly seen that the code can be reconstructed and the code that is no more required can be either deleted or commented (if possibility is there for use in future).

    0 讨论(0)
提交回复
热议问题