funeralcrasher: (Default)
funeralcrasher ([personal profile] funeralcrasher) wrote2008-06-23 10:33 am

Stumped.

$num = 10;
function multiply()
{
$num = $num * 10;
}
multiply();
echo $num;


This prints "10" to the screen.

$num = $num * 10;
echo $num;


But this prints "0".

Why is that?

[identity profile] outintospace.livejournal.com 2008-06-23 03:12 pm (UTC)(link)
Because $num is not returned by the function. When multiply() is called, it's not updating the reference to $num. It's creating a new variable with method scope called $num.