simboski19 Posted December 16, 2011 Share Posted December 16, 2011 Hi, As the title suggests I am unsure on how to first run a query which stores values into an array. I then need to run a function multiple times but use the array within the function. How is this possible? I have had no luck figuring it out yet. 1. RUN QUERY 2. BUILD ARRAY USING QUERY RESULTS 3. RUN FUNCTION MULTIPLE TIMES 4. WITHIN FUNCTION I NEED TO USE ARRAY Many thanks Simon Quote Link to comment https://forums.phpfreaks.com/topic/253314-how-do-i-make-an-array-global-to-use-in-multiple-functions/ Share on other sites More sharing options...
premiso Posted December 16, 2011 Share Posted December 16, 2011 You can use the $_GLOBALS $_GLOBALS['yourarray'] = array('test'); function myFunc() { $array = $_GLOBALS['yourarray']; } There are better ways to do it, however, such as passing it as a parameter: $array = array('test'); myFunc($array); function myFunc($array) { print_r($array); } But there you have it. Quote Link to comment https://forums.phpfreaks.com/topic/253314-how-do-i-make-an-array-global-to-use-in-multiple-functions/#findComment-1298574 Share on other sites More sharing options...
simboski19 Posted December 16, 2011 Author Share Posted December 16, 2011 Great thanks. I'll try both now. Using $_GLOBALS, am I right in thinking this can then be used anywhere in the php file in multiple functions? Thanks Simon Quote Link to comment https://forums.phpfreaks.com/topic/253314-how-do-i-make-an-array-global-to-use-in-multiple-functions/#findComment-1298576 Share on other sites More sharing options...
premiso Posted December 16, 2011 Share Posted December 16, 2011 Using $_GLOBALS, am I right in thinking this can then be used anywhere in the php file in multiple functions? I don't think I would have pointed it out otherwise, but who knows. Give it a shot. Quote Link to comment https://forums.phpfreaks.com/topic/253314-how-do-i-make-an-array-global-to-use-in-multiple-functions/#findComment-1298588 Share on other sites More sharing options...
simboski19 Posted December 16, 2011 Author Share Posted December 16, 2011 Works like a treat. Many thanks Simon Quote Link to comment https://forums.phpfreaks.com/topic/253314-how-do-i-make-an-array-global-to-use-in-multiple-functions/#findComment-1298590 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.