Reputation: 31
How can we pass the variable value to function without using any parameter? Once we run the script variable value can be echo within the function.
Upvotes: 0
Views: 78
Reputation: 15603
You can access the value of variable by declaring the variable as global variable.
Upvotes: 0
Reputation: 11240
You could use the keyword global
, although I think you shouldn't.
Example:
$a = 'foo';
bar();
function bar(){
global $a;
echo $a;
}
Above code will print "foo";
Again, I really think you should not use this and come up with some other implementation that doesn't require the use of global variables.
Upvotes: 1