Is there a function for switching/inverting boolean value in PHP?
boolean
Like... a shortcut for:
if($boolean === true){ $boolean = false; }else{ $boolean = true; }
Yes:
$boolean = !$boolean;
if it's not a boolean value, you can use the ternary construction:
$int = ($some_condition ? 1 : 2); // if $some_condition is true, set 1 // otherwise set 2
2.1m questions
2.1m answers
60 comments
57.0k users