News:

Tekforums.net - The improved home of Tekforums! :D

Main Menu

Correct Format for - foreach + two statments

Started by neXus, June 06, 2007, 18:41:03 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

neXus

Just to recap that a foreach loop to access array data is..


foreach ($_POST[checkbox] as $bgvalue) {
//Do Stuff
}


Which is fine, but say you have some data from a form that has two elements of multiple data that need to be used - basically two arrays

(In my case its a lot of choices with two data elements of each choice)

I thought the form for it was...


foreach ($_POST[checkbox] as $bgvalue;  $_POST[hiddenlink] as $lkvalue) {
//do stuff
}


Which it is not as you get the error..
Parse error: parse error, unexpected ;, expecting )

Anyone know the correct format for that please?

Thanks

cornet

Not sure where you got that idea from... you want nested foreach loops...


foreach ($_POST[checkbox] as $bgvalue) {
   foreach ($_POST[hiddenlink] as $lkvalue) {

       //do stuff

    }
}



Cornet

neXus

Quote from: cornetNot sure where you got that idea from... you want nested foreach loops...


foreach ($_POST[checkbox] as $bgvalue) {
   foreach ($_POST[hiddenlink] as $lkvalue) {

       //do stuff

    }
}



Cornet

Nope, becuase that returns 4 lots of 1 item each time when it should only be the once