$var inside 2 functions

Hi, I want to ask a conceptual question regarding php:

if I have the following code, why is the returned value zero (0)?

[php]

class example {

function a()
{
$x = 0;
$this->b();
return $x;
}

function b()
{
$x = $x + 1;
}

}
[/php]

Because variable $x in function a() and variable $x in function b() are two different variables, despite of that you named them the same “x”.

Great admin, thanks!
gtb

Sponsor our Newsletter | Privacy Policy | Terms of Service