I made two ways to change the value a
and b
, but which is more optimized, taking this example to other languages like desktop or web.
Without using auxiliary variable:
$a = 10;
$b = 5;
$a = $b+$a;
$b = $a-$b;
$a -= $b;
Using auxiliary variable:
$a = 10;
$b = 5;
$c = $a;
$a = $b;
$b = $c;