I have a function that prints a variable that is on the page that the function is being called from but since functions don't do that, the variable appears as text. How can I make it so that when I echo out the variable, it finds the variable from the file where the function is being called from and prints it the way it should be. Thanks.
Functions have their own scope so they don't see regular variables outside their scope. You can pass the variable to the function or use a define: define("myVar", "hello world"); function foo(){ print constant("myVar"); } foo();
the problem is that I have many variables that need to be printed so is there any way to do this without defining which variables? Or perhaps only make a global variable out of variables in a specific string?
I personally would pass any variables I need to the function, but you could always do: $t = "hello world"; function foo(){ global $t; print $t; } foo(); PHP: A bit of a "black magic" method of doing things, not my style.
You don't under stand. I have almost 50 variables, that all change from time to time. I can't make 50 some global variables. All of the variables are printed in a function through eval but since there not global they don't display. Can i make only the ones printed with eval global?