salman_ahad@yahoo.com Posted October 26, 2009 Share Posted October 26, 2009 I have a variable $result I want to use it outside my loop, how can I?? ... foreach ($sent as $result) { ... ... //$result undergoes some calculation. } ... foreach ($result as $result2) I want to use $result again later in the code... { echo $result2; } It gives me Invalid argument supplied for foreach()... Quote Link to comment Share on other sites More sharing options...
ILMV Posted October 26, 2009 Share Posted October 26, 2009 You cannot access that variable outside of that loop, simple as that. You would need access it from within the 1st loop. Quote Link to comment Share on other sites More sharing options...
smerny Posted October 26, 2009 Share Posted October 26, 2009 what value are you hoping $result will have for the second loop? what exactly are you trying to do? depending on that, you could put the second loop within the first... otherwise store info you want to use for the second loop into a separate list while still in the first loop Quote Link to comment Share on other sites More sharing options...
Derleek Posted October 26, 2009 Share Posted October 26, 2009 I could be wrong here, because I recently just stumbled upon this neat little function of PHP and have not had much time to explore the practical uses of it. But perhaps look into using the php reference functionality. Not sure exactly if this is standards compliant or whatever. But it is a potential solution. Quote Link to comment 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.