Skip to content

Instantly share code, notes, and snippets.

@zeuxisoo
Created March 24, 2011 05:49
Show Gist options
  • Save zeuxisoo/884640 to your computer and use it in GitHub Desktop.
Save zeuxisoo/884640 to your computer and use it in GitHub Desktop.
Is best way to exchange variable?
<?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