Swap Two number Program in PHP

Advertisements

Prev Tutorial Next Tutorial

Swap Two number Program in PHP

Swap two number with each other means interchange their value. Suppose you have two number a and b a contain 10 and b contain value 20 after swap their value, a have 20 and b have 10.

Swap two number using third variable program in PHP

<?php

$a=10;
$b=20;

echo "Value of a: $a</br>";
echo "Value of b: $b</br>";

$temp=$a;
$a=$b;
$b=$temp;

echo "Value of a: $a</br>";
echo "Value of b: $b</br>";

?>

Output

	
Value of a: 10
Value of b: 20
Value of a: 20
Value of b: 10

Swap two number without using third variable program in PHP

<?php

$a=10;
$b=20;

echo "Value of a: $a</br>";
echo "Value of b: $b</br>";

$a=$a+$b;
$b=$a-$b;
$a=$a-$b;

echo "Value of a: $a</br>";
echo "Value of b: $b</br>";

?>

Output

	
Value of a: 10
Value of b: 20
Value of a: 20
Value of b: 10

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements