Forum Moderators: coopster

Message Too Old, No Replies

array_pop($_POST) knocks out all the keys & values in the array..

It's supposed to only boot the last row, what gives?

         

crowthercm

6:46 pm on Aug 5, 2003 (gmt 0)

10+ Year Member



Is there something I'm doing wrong? The syntax for this function seemed pretty straight forward but it's not working like I was expecting it to. Namely, I just want to remove the last row from the array.
Thx,
Chris

dmorison

7:09 pm on Aug 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Chris,

I just did a quick test and it worked as expected. Can you post the code excerpt that is not working...?

crowthercm

7:22 pm on Aug 5, 2003 (gmt 0)

10+ Year Member



Heya Dmorison,

Thanks for the quick reply. I was annoyed and already went ahead and wrote a write around for it.

The code I was using was something like:

array_pop($_POST);

$x = 0;
while ($x < sizeof($_POST)):
list($key,$value) = each($_POST);
echo "Key: $key, Value: $value <br />";
$x++;
endwhile;

The output I was getting was:
Key, Value
Key, Value
Key, Value
etc.

When I removed the array_pop line, the while loop displayed all the values correctly. I just needed to dump the submit and hidden values so I didn't bother outputting the popped value into a variable.

Chris

jatar_k

7:36 pm on Aug 5, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I tend to use this

foreach($_POST as $key => $value){
echo "Key: $key, Value: $value <br />";
}

crowthercm

7:55 pm on Aug 5, 2003 (gmt 0)

10+ Year Member



Cool, yes that's much simpler (: Any ideas on why I'm having problems with array_pop?

jatar_k

9:51 pm on Aug 5, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



not really but either of the other solutions will work quite well. ;)

Xuefer

1:51 am on Aug 6, 2003 (gmt 0)

10+ Year Member



Key, Value
should be:
Key: , Value:
u gave the worng test result

correction to script:
reset($_POST);
while (list($key,$value) = each($_POST)) {
echo "Key: $key, Value: $value <br />";
}

crowthercm

3:29 pm on Aug 7, 2003 (gmt 0)

10+ Year Member



Xuefer,

Right, output was as you specified. You're also correct that the array needed to be reset before array_pop would work properly.
Thanks