swap
swap
Swap Values Without Temporary Varaibles In PHP
Tue, 10/28/2008 - 10:59 | by philipnorton42I have talked about swapping values without a temporary third variable before, but there is another way to do this which doesn't make the code unreadable. This is by using the list() function in the following way.
Swap Values Without A Third Variable In PHP
Tue, 08/19/2008 - 15:45 | by philipnorton42Swapping variable values is important in sorting algorithms when you want to swap a higher value with a lower one. The usual action of variable assignment is to take the first value, put the value of this variable in a temporary variable and then assign the value of the second variable to the first one. As in the following code:
$tmp = $a; $a = $b; $b = $tmp;
This can be rewritten using the bitwise Xor (exclusive or) operator.