Skip to content

Instantly share code, notes, and snippets.

@v9n
Created September 18, 2012 16:26
Show Gist options
  • Select an option

  • Save v9n/3744098 to your computer and use it in GitHub Desktop.

Select an option

Save v9n/3744098 to your computer and use it in GitHub Desktop.
swap value of 2 vars without using any extra var
<?php
$a = 1;
$b = 2;
list($a, $b) = array($b, $a);
print "a=$a, b=$b\n";
a = 1
b = 2
a, b = b, a
puts "a=#{a}, b=#{b}\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment