Swap two variables in php
<?php
// using array and list features
echo "a=".$a=12;
echo "<br>";
echo "b=".$b=2;
echo "<br>";
list($b,$a)=array($a,$b);
echo "A".$a;
echo "<br>";
echo $b;
echo "<br>";
// using simple two php variables
echo "A==".$a=4;
echo "<br>B==".$b=5;
$b=$a+$b;
echo "<br>A=";
echo $a=$b-$a;
echo "<br>B=";
echo $b=$b-$a;
?>
// using array and list features
echo "a=".$a=12;
echo "<br>";
echo "b=".$b=2;
echo "<br>";
list($b,$a)=array($a,$b);
echo "A".$a;
echo "<br>";
echo $b;
echo "<br>";
// using simple two php variables
echo "A==".$a=4;
echo "<br>B==".$b=5;
$b=$a+$b;
echo "<br>A=";
echo $a=$b-$a;
echo "<br>B=";
echo $b=$b-$a;
?>
Comments
Post a Comment