Peter6528 Peter6528 - 1 year ago 73
PHP Question

Two functions with the same variable

I have 2 functions, with the same variable:

function fs1(){
$username = 1;
return $username;

function fs2(){
$username = 2;
return $username;

$pineapple = fs2();
$apple = fs1();

If I call both functions, can I get an error like the username variable value is changed, or something else?

Answer Source


Variables defined inside functions are available only within the function scope.

They are not accessible outside.

Check this link provided by Rizier123 to see the documentation for PHP variable scope.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download