• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Very EASY php question

Thanks, though I'm really trying to get that array to function as a global... what's wrong with making that array global? (except that it isn't working, that is!)

The php script I'm writing would have alot of redundancy if I can't get arrays to work as such. (the function I'm writing uses many global variables)
 
The alternative is to learn how to use objects. Then you can intialize them and use them. Or pass variables to your functions like a good programer. Global variables are like goto statements. There is never a good reason to use them, except for that one exception, but I"m not going to tell you. Cause if you dont know its a good time to use them, then it's not.
 
If you want to use a global variable within a function (which, as notfred correctly points out, is not usually good practice) you need to tell the function that variable is global rather than local. So add a line global $the_array; before you assign the value to $rtrn.

Using lots of globals is discouraged because it quickly leads to code thats difficult to understand and maintain. When your functions are all operating on globals, it's hard to follow the code path because you have to follow each subroutine you call to make sure it's not surreptitiously changing a global variable while you're not looking.
 
Back
Top