0
Why is the error?
<?php $name = 'David'; function getName() { echo $name; } getName(); // Error: Undefined variable: name ?>
2 ответов
+ 2
It's because variables can have different scope. In your case in the function, variable name is not defined, here name is local function scope variable. You can see here a possible solution with global scope variables => accessible from anywhere.
https://code.sololearn.com/wDf0Sxr3HGeq/?ref=app
+ 1