View Single Post
Old 03-13-2008, 10:43 PM   #1 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Arrow 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
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
The Following User Says Thank You to Alan @ CIT For This Useful Post:
Devels (03-14-2008)