Friday, 9 December 2016

Swap variable values in php


Swap variable values in php

<?php
$a = 40;
$b = 50;

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

echo $a;
echo $b;

OR

Swap values without third variable

$a = 40;
$b = 50;

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

echo $a;
echo $b;

?>

No comments: