![]() |
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:
PHP Code:
Hopefully usefull to someone :-) Alan |
I haven't tried this but it seems like the following would work as well. It's a little easier to understand.
PHP Code:
|
I've always done it the way Eric showed. ;-)
|
What you're doing there is utilizing the bitwise 'xor' operator. It's a little bit in depth to explain this operation in detail so we'll go with "it just works"... sort of. Since we're only working with one bit (0 or 1) the expression works something like:
PHP Code:
PHP Code:
|
This is the method I usually use:
Code:
$var = ($var) ? false : true; |
Handy to know, but why are you replying to a thread that is over 3 years old !
|
Oops... I don't look at post dates that much XD
|
| All times are GMT. The time now is 01:34 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0