Values & References14 / 16
Up next

Swap via references

<?php
declare(strict_types=1);
// references let a function swap caller variables
function swap(&$a, &$b): void {
    [$a, $b] = [$b, $a];
}
$x = 1;
$y = 2;
swap($x, $y);
echo "$x $y\n";
What you're solving

two &-params exchange values