Usage of ^ within a conditional statement?

Hi there

I’ve been using PHP for a while now and use ternary operators quite a lot, but I’ve come across something that I have never seen before. Can anyone tell me/point me to documentation explaining what the ^ symbol is doing in this statement?

[php]$show = is_user_logged_in() ^ ( ‘public’ == $atts[‘visible_to’] );[/php]

Through some debugging, I’ve found that it seems to return true if the two conditions either side of it are opposite, but I’d love to know more about this, as I can’t find any documentation on it.

Cheers
Phil

bitwise XOR equals. It basically toggles a flag because I’m getting $flag is a power-of-2. To give you an example:

[php]$a = 5; // binary 0101
$b = 4; // binary 0100
$a ^= $b; // now 1, binary 0001[/php]

So the third bit has been flipped. Again:

[php]$a ^= $b; // now 5, binary 0101[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service