03-13-2008, 10:43 PM
|
#1 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
Toggling true/false variables
Hi all,
Just a quick tip for you all
I'm sure that we've all used something like the following before to toggle a bool variable:
PHP Code:
if ($myVar == true)
{
$myVar = false;
}
else
{
$myVar = true;
}
Well you'll be please to know that there is a shorter way of doing it
PHP Code:
$myVar ^= true;
This does exactly the same as our if() block above - if $myVar is false, it sets it to true. If it is true, it sets it to false.
Hopefully usefull to someone
Alan
|
|
|