PHP Learning : Swapping two variables - Publik Talk

Breaking

An informative website for every one.

Post Top Ad

Post Top Ad

Wednesday, August 2, 2017

PHP Learning : Swapping two variables

Description:

Swapping two variables refers to mutually exchanging the values of the variables.
Generally, this is done with the data in memory.
The simplest method to swap two variables is to use a third temporary variable :

Code:

<?php

$a = 15;

$b = 27;

echo "The number before swapping is:</br>";

echo "Number a =".$a." and b=".$b;

$temp = $a;

$a = $b;

$b = $temp;

echo "<br>The number after swapping is:</br>";

echo "Number a =".$a." and b=".$b;

?>



Output:


No comments:

Post a Comment

Post Top Ad