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;
?>
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