Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I'm trying to swap two number using operator but not able to swap the number please help to solve

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading