The XOR swap lets you swap the value of integer variables without using a temporary variable, it's also slightly faster.
PHP:
-
$x ^= $y;
-
$y ^= $x;
-
$x ^= $y;
I can't actually think of a good reason Why you'd want to use this in PHP since memory isn't normally a big issue, however it might be good for showing off
.
// Pete Graham xXx
Comments 1
$x^=$y^=$x^=$y;
Posted 24 Nov 2007 at 3:22 pm ¶Trackbacks & Pingbacks 1
[...] Much like the PHP XOR swap there’s no real reason this is any better than using a temporary variable, but you might be able to impress chicks with it or something. [...]
Post a Comment