Peter6528 Peter6528 - 1 year ago 68
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?

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.