Peter6528 Peter6528 - 5 months ago 39
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?



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.