switching boolean value in PHP [duplicate]
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.
精彩评论