Created
March 24, 2011 05:49
-
-
Save zeuxisoo/884640 to your computer and use it in GitHub Desktop.
Is best way to exchange variable?
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
<?php | |
/* | |
* Code A | |
* ---- | |
* It also create temp variable, but not see in coding? | |
*/ | |
list($a, $b) = array($b, $a); | |
/* | |
*Code B | |
* ---- | |
* Not temp variable, better than Code A? | |
*/ | |
$a = 7; | |
$b = 3; | |
$a = $a + $b; // a = (10) | |
$b = $a - $b; // b = (7) | |
$a = $a - $b; // a = (3) | |
/* | |
So: | |
--------- | |
$a = 3 | |
$b = 7 | |
*/ | |
/* | |
* Reference: http://www.laruence.com/2011/03/24/858.html | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment