John John - 6 months ago 72
PHP Question

PHP Flip Boolean Value

I have a boolean value that I would like to flip between true and false. The basic implementation of this is:

if ($my_boolean) {
$my_boolean = false;
else {
$my_boolean = true;

Is there a way to simplify this and reduce the number of lines of code?


You can use this:

$my_boolean = !$my_boolean;