I getting a php error
undefined variable $fname
$fname="John";
function getThis()
{
$complete_name= $fname."Kerry";
echo $complete_name;}
getThis();
Any help in the right direction is much appriciated! Thanks
you have a variable scoping issue
Variables defined outside the function have Global scope and they can not be used inside a function, If you want to use them inside a function You must write the global keyword before the variable name.
global $fname;
And in your case
I noticed that Variable $fname is defined outside the function, and it has a global scope, if you use this inside the function ,then it will throw error.
Try this
$fname="John";
function getThis()
{ global $fname;
$complete_name= $fname."Kerry";
echo $complete_name;}
getThis();
Source :
Use This :-
$fname="John";
function getThis()
{
global $fname;
$complete_name= $fname."Kerry";
echo $complete_name;
}
getThis();
You can not access variables inside function which declared out side, you have to use global keyword to use....
$fname="John";
function getThis()
{
global $fname;
$complete_name= $fname."Kerry";
echo $complete_name;}
getThis();
globalkeyword for$fname