Tekforums

Chat => Entertainment & Technology => Topic started by: neXus on June 06, 2007, 18:41:03 PM

Title: Correct Format for - foreach + two statments
Post by: neXus on June 06, 2007, 18:41:03 PM
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
Title: Re:Correct Format for - foreach + two statments
Post by: cornet on June 07, 2007, 00:03:59 AM
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
Title: Re:Correct Format for - foreach + two statments
Post by: neXus on June 07, 2007, 02:06:20 AM
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