PHP - toggle state
If the result is allowed to be a boolean (and it does not have to be an integer swap) you can use the negation operator:
<?php
$state = 0;
var_dump(!$state);
$state = 1;
var_dump(!$state);
Output:
bool(true)
bool(false)
You can do:
$state = 1 - $state;
Try this code :
$state = !$state