#native_company# #native_desc#
#native_cta#

Swap Values without using third variable

By Abdullah Ramazanoglu
on May 31, 2007

Version: 1.1

Type: Function

Category: Algorithms

License: GNU General Public License

Description: Simple script for swaping 2 variables without using third variable.

<?

function my_swap($a,$b)
{
	echo "Before Swap<br>";
	echo "a : ".$a."<br>";
	echo "b : ".$b;

/*	$temp = $a;
	$a = $b;
	$b=$temp;*/

// Above this line is ditto original v 1.0
// Change starts (should work on any scalar types of equal length)
$a ^= $b;
$b ^= $a;
$a ^= $b;
// Change ends
// Below this line is ditto original v 1.0

	echo "<br><br>After Swap<br>";
	echo "a : ".$a."<br>";
	echo "b : ".$b;
}

my_swap(513,7231);
?>