开发者

switching boolean value in PHP [duplicate]

This question already has answers here: Boolean value switch/invert 开发者_JAVA技巧 (8 answers) Closed 7 years ago.

Let's say I have the following function which should return True if valid and False if invalid.

Is there a shortcut to return the 'opposite' of the boolean $this->errors?

Should I use a one-line if statement or is there another possibilty?

So if $this->errors is false I want it to return true :P

function valid() {

    $this->errors = False;

    if ($somethingiswrong) {
        $this->errors = True;
    }

    return $this->errors;
}

EDIT

OMG How come I never see the right questions/answers when I use the search option. But find the right answers when I already posted :P

return !$this->errors;

Is what I was looking for.


return !$this->errors;

! is logical negation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜