I was studying for my finals and I came across this question:
write the output after running this code.
<?php
function swap($x, $y)
{
$x = $x + 1;
$y = $y + 2;
return $x * $y;
}
$a = 3;
$b = swap($a, $a);
print "$a, $b";
$b = swap(&$a, &$a);
print "$a, $b";
?>
I understand exactly what this code does, however after I ran it I got a completely different answer to what I answered with and I really don’t understand the output.
The output I got was 3, 206, 36.
Could someone explain the output to me?
What you get is actually 3, 20, 6, 36 which is the correct answer. If you don’t understand why you got “206” instead of “20” and “6” it is just because you have not a space after the first
print. That’s it.