When we need to swap the values of two variables, we use a third variable temporarily to hold the data between swapping. Something like this:
<?php $tmp = $a; $a = $b; $b = $tmp; ?>
Here is another way without using a temp or a third variable.
<?php list($b, $a) = array($a, $b); ?>
And if you want to make it a function:
<?php
function swapValues(&$a, &$b) {
list($b, $a) = array($a, $b);
}
$a = 10;
$b = 20;
swapValues($a, $b);
?>



In that case not creat temp variable, but all the same set(create) array without name.