Created
February 25, 2013 14:04
-
-
Save adamneilson/5029974 to your computer and use it in GitHub Desktop.
Swap variables values without the use of a third trivial interview question.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set the initial values | |
$a = 100; | |
$b = 200; | |
// swap them! | |
$a = $a + $b; // $a == 300 | |
$b = $a - $b; // $b == 100 | |
$a = $a - $b; // $a == 200 | |
// done! | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment