This method will work for any type of variable:
$a = 5; $b = 6; list($a, $b) = array($b, $a); print $a . ',' . $b;
Output:
6,5
Another easy way (which works only for numbers, not strings / arrays / etc) -
$a = $a + $b; // 5 + 6 = 11 $b = $a - $b; // 11 - 6 = 5 $a = $a - $b; // 11 - 5 = 6 print $a . ',' . $b;
Output:
6,5
Jay
source share