Here, I’m trying to swap the number using PHP but not able to swap.
How to solve that problem.
My Code :
<?php
$a = 45;
$b = 78;
echo "Before swapping:<br><br>";
echo "a =".$a." b=".$b;
echo "<br/><br/>";
// Swapping Logic
$a=$a+$b;
$b=$a-$b;
$a=$a+$b;
echo "After swapping:<br><br>";
echo "a =".$a." b=".$b;
?>
I’m a beginner in php just learning about logic but getting exception so any body can help how to solve it?
>Solution :
Please replace your code
// Swapping Logic
$a=$a+$b;
$b=$a-$b;
$a=$a+$b;
with
$a=$a+$b;
$b=$a-$b;
$a=$a-$b;