...

View Full Version : foreach loops



chesneil
02-25-2008, 06:59 AM
I have the following setup. I want to pass an array from the lower foreach loop to the upper foreach loop when I submit the former. I don't really know what I'm doing -relying more on logic than knowledge of syntax - but this doesn't work. What am I doing wrong? Thanks guys.


foreach ($_POST['emailto'] as $send) {
echo $send;
}
exit();

$i=0;
$emailto=array();

foreach ($_POST['email'] as $sendto) {
echo("<input type='hidden' name='emailto[".$i."]' value='".$sendto."'>");
$i++;
// and other stuff that works OK
}

idalatob
02-25-2008, 09:55 AM
I dont think you can have multiple values for one array key.... So for example when you take $_POST['email'] there will only be one value.... you cannot run a foreach command on that.

Try changing your code so that you run a foreach on only the $_POST. and not on individual keys.

eg.


foreach ($_POST as $value){
echo($value);
}
//not
foreach ($_POST['some_value']){
}


or just try re-evaluating your code.

chesneil
02-25-2008, 01:18 PM
Yeah, that didn't work out at all so I completely changed the code. Thanks anyway.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum