Can someone please enlighten this old idiot before I end up jumping off our office roof in frustration.
How I can share an array between multiple functions within a given script? Allow me to explain what I am trying to achieve...
The script processes order files uploaded by suppliers. Whenever the script finds a valid line, it calls a function that starts to build the final order, updating various fields in a main array ($IN['order-code'], $IN['quantity'], etc). Now, depending upon what it finds in the update file, it may call varous validation routines which in turn need to update the main $IN array, depending the options found. Finally, once the order has been built, another function uses the data in the $IN array to write the final order to the main tables.
In practise, there are a couple of different central arrays. I had hoped that declaring each as global at the top of each function would allow the data to be shared and updated by each function - but this doesn't always seem to be the case. Passing the arrays in the function parameters is fine when the data only needs to be read, but makes it cumbersom/unreliable when the function also needs to update any elements of the arrays.
Any help in explaining the best approach - in layman's language please - would be much appreciated.
Thanks in anticipation.