Peter6528 Peter6528 - 3 months ago 32
PHP Question

PHP 2 functions whith 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.