Jump to content

use variable outside loop ???


Recommended Posts

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()...

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.