Swap two variables value without using third variable in php?
We can swamp two variable with the use of php function
<?php $a='sagar'; $b='deepak';
list($a,$b) = array($b,$a);
echo $a.'-'.$b; ?>
deepak-sagar
We can swap two variable with the use of XOR method too
<?php
$a='11111'; $b='22222';
$a = $a ^ $b;
$b = $a ^ $b;
$a = $a ^ $b;
echo $a;
echo $b;
?>
We can swap two variable with the use of our logic too
<?php
<?php $a='sagar'; $b='deepak';
list($a,$b) = array($b,$a);
echo $a.'-'.$b; ?>
deepak-sagar
We can swap two variable with the use of XOR method too
<?php
$a='11111'; $b='22222';
$a = $a ^ $b;
$b = $a ^ $b;
$a = $a ^ $b;
echo $a;
echo $b;
?>
We can swap two variable with the use of our logic too
<?php
$a='11111'; $b='22222';
$a = $a + $b; $b = $a - $b; $a = $a - $b;
?>
anther one is here
$a = $a * $b; $b = $a / $b; $a = $a / $b;
Comments
Post a Comment