John John - 1 year ago 123
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?

Answer Source

You can use this:

$my_boolean = !$my_boolean;