Showing posts with label Swap variable values in php without use third variable. Show all posts
Showing posts with label Swap variable values in php without use third variable. Show all posts

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;

?>