funeralcrasher: (Default)
$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?

Date: 2008-06-23 02:53 pm (UTC)From: [identity profile] pkbarbiedoll.livejournal.com
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?

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

Profile

funeralcrasher: (Default)
funeralcrasher

June 2020

S M T W T F S
 123456
78910111213
141516 1718 1920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 30th, 2025 06:42 am
Powered by Dreamwidth Studios