$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)?


class example {

function a()
$x = 0;
return $x;

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


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!

Sponsor our Newsletter | Privacy Policy | Terms of Service