Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Php
list($b, $a ) = [ $a, $b ];

list() creates a LVAL array context. The RVAL is an array literal made from scalars.
$tmp = $a;
$a = $b;
$b = $tmp;

Using a third variable is the only way to keep performance good.
[ $b, $a ] = [ $a, $b ];

Using destructuring
procedure swap(a, b: in out Integer)
is
    temp : Integer;
begin
    temp := a;
    a := b;
    b := temp;
end swap;

New implementation...
programming-idioms.org