Jump to content

[SOLVED] Storing foreach results in an array


NathanLedet

Recommended Posts

Hi, I have a form with check boxes.  When the form is submitted, i use the following code to retrieve the data:

 

$files = $_POST['files'];
foreach ($files as $f => $value){
echo "$f <br />"; 

 

so everything that was checked will display as it should, but now I need to display that information in more than one location...and to me, it doesn't make sense to use a foreach statement every time I want to display that information...

 

is it possible to use that foreach statement one time, and then store the results in an array that I can just plop anywhere I need?

 

thanks!!

is it possible to use that foreach statement one time, and then store the results in an array that I can just plop anywhere I need?

 

If you used another array you would still need to iterate through it again to display its contents. Maybe you want to store the results in a string?

 

$files = $_POST['files'];
foreach ($files as $f => $value) {
  $str .= $f . "<br />";
}

echo $str;

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.