Jump to content

use variable outside loop ???


salman_ahad@yahoo.com

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
https://forums.phpfreaks.com/topic/179067-use-variable-outside-loop/
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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.