[wd_asp elements=’search’ ratio=’100%’ id=1]

Give a function access to outside variable

8th September 2016

Php - Miscellaneous

php codehaven

By default, when you are inside a function, you do not have access to the outer variables.

If you want your function to have access to an outer variable, you have to declare it as global, inside the function

$myval = "hi";

function myfunction(){
global $myval;
echo $myval;
}