Q:

Write a PHP program to swap two variables

belongs to collection: PHP basic programs with examples

0

Write a PHP program to swap two variables

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

The number before swapping is:
num1 = 20 and num2= 30
The number after swapping is: 
num1 = 30 and num2= 20

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a PHP program to check if a number is an Arm... >>
<< Write a PHP function to test whether a number is g...