Boolean value switch/invert

Solution 1:

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

Solution 2:

What about using the Absolute Value function abs() , $val can be "1" or "0" and you want to invert it:

$val = abs($val-=1);

The logic:

Always subtracting "1" from the number and eliminating the "sign".

1 - 1 = 0
abs(0) = 0

0 - 1 = -1
abs(-1) = 1