Any way to break if statement in PHP?

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

    Because you can break out of a do/while loop, let us "do" one round. With a while(false) at the end, the condition is never true and will not repeat, again.

    do
    {
        $subjectText = trim(filter_input(INPUT_POST, 'subject'));
        if(!$subjectText)
        {
            $smallInfo = 'Please give a subject.';
            break;
        }
    
        $messageText = trim(filter_input(INPUT_POST, 'message'));
        if(!$messageText)
        {
            $smallInfo = 'Please supply a message.';
            break;
        }
    } while(false);
    

提交回复
热议问题