Forum Moderators: coopster

Message Too Old, No Replies

Foreach loop retaining array structure

loop problems

         

Matthew1980

7:44 pm on May 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there people of the forum,

I need a pointer as I cannot resolve this for some reason:-

foreach($_POST as $key){
//iterate through each post key
}

foreach($_POST as $key=>value){
//iterate through each post key& value
}


I am sure as this is valid syntax, but I get the error "T_PAAMAYIM_NEKUDOTAYIM" which according to the php.net manual means double colon (I think) In Hebrew, my issue is, I want to iterate through a $_POST array in a foreach keeping the keys & values in tact. I hope this makes sense.

The reason for this is I am attempting something in a class for the first time, and I cannot think of another way to approach this.

If anyone has a better approach to this, feel free to tell me :)

Cheers,
MRb

mooger35

7:46 pm on May 4, 2010 (gmt 0)

10+ Year Member



foreach($_POST as $key){
//iterate through each post key
}

In this case $key = value.

foreach($_POST as $key=>value){
//iterate through each post key& value
}

you are missing the $ before value. It should be

foreach($_POST as $key => $value){
//iterate through each post key& value
}


[php.net...]

Matthew1980

7:58 pm on May 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there mooger35,

Well, I should have noticed that! Right, I think I shall have some coffee and continue this tomorrow.

Thanks for pointing that out to me, "wood for the tree's" I think is the fitting phrase there :)

Cheers,
MRb