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.
2
-
4Why would you want to do that? What's wrong with parameters?Karl Knechtel– Karl Knechtel2011-12-07 06:10:56 +00:00Commented Dec 7, 2011 at 6:10
-
The only solution would be to use a global variable, but I don't really see the need for that. Maybe if you expand your question it would be easier to understand what you are trying to donico– nico2011-12-13 11:04:18 +00:00Commented Dec 13, 2011 at 11:04
Add a comment
|
2 Answers
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.