I'm writing a function in PHP , but I try to use certain variables and seems to not exist. Are variables that I created outside the function and I would like to use within the function , but without passing them as a parameter.
Answer by Miguel Angel Alvarez In PHP, within a function, in principle, there are only variables you have created within it. Thus , it is normal that you can not access variables created outside there that function.
In PHP , variables declared externally to a function are global and created in a function are local variables. However, PHP provides us with a couple of mechanisms for within functions can use global variables. The ? Global? Array $ GLOBALS and the declaration of global variables ? at the beginning of the function.
All the field variables and the use of global variables inside a function are explained in our manual PHP.