Write a PHP program to swap two variables

Introduction

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following excercise..

<?php
$num1 = 20;
$num2 = 30;
 
echo "\nThe number before swapping is:\n";
echo "num1 = ".$num1." and num2= ".$num2 ;
 
$temp = $num1;
$num1 = $num2;
$num2 = $temp;
 
echo "\nThe number after swapping is: \n";
echo "num1 = ".$num1." and num2= ".$num2."\n";
?>

Result

Write a PHP program to swap two variables
Write a PHP program to swap two variables

Leave a Comment