bluebyyou Posted June 25, 2007 Share Posted June 25, 2007 Can I use AND or && in a foreach loop, like this: foreach ($_POST['day'] as $day && $_POST['event'] as $event) { $query = "INSERT INTO event(year,day,event) VALUES('$_POST[year]','$day','$event')"; } Or is there some other way to do this? Quote Link to comment Share on other sites More sharing options...
btherl Posted June 25, 2007 Share Posted June 25, 2007 Unfortunately, no. Here are two alternate styles. # This one only works for arrays numbered consecutively from 0 $i = 0; $arr_len = count($arr); for ($i = 0; $i < $arr_len; $i++) { print $arr[$i]; print $arr2[$i]; } # This one works for anything reset($arr); reset($arr2); while (list($arr_key, $arr_val) = each($arr)) { list($arr2_key, $arr2_val) = each($arr2); } In both cases, the length of the loop is decided by the length of $arr, in the case of a mismatch in array lengths. Quote Link to comment Share on other sites More sharing options...
bluebyyou Posted June 25, 2007 Author Share Posted June 25, 2007 Thank you that did it. 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.