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] pkbarbiedoll.livejournal.com 2008-06-23 02:53 pm (UTC)(link)
good catch.. I made a type-o when posting.

The problem remains, though - if $x * 2 = 0 (where x is not set), then why is the function returning a number instead of 0?

[identity profile] skywayman.livejournal.com 2008-06-23 04:57 pm (UTC)(link)
Variable scope. See my response.