Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Friday, February 12, 2010

Swapping two integer values without using temporary variables in php


echo '
';
echo 'X:

';
echo 'Y:

';
echo '

';
echo '

';

$x = $_POST['x'];
$y = $_POST['y'];

function swap(&$x,&$y){
$x ^= $y ^= $x ^= $y;
}

swap($x,$y);

print "X = " .$x. "

";
print "Y = " .$y. "";


?>