Jump to content

I don't understand how array_pop is supposed to work on a SESSION array


Recommended Posts

I want to use array_pop to remove the last item added to the SESSION array. So it would remove the REQUEST item. The problem is that nothing is left in the session array because I pop off the last item each time that the form is submitted. Maybe I need to use array_push to push the popped items back on to the SESSION array after the logic has been applied. I don't understand how array_pop is supposed to work on a SESSION array. Can anyone explain to me what behaviour to expect? I expected to get a SESSION array with the REQUEST item removed but I thought that I would still have all of my SESSION items.
 

array_pop is just an array function that works on any array.  Using it on a $_SESSION array is no different than any other array.  If you pop something off an array it is no longer a member of that array and that's that.   And using it on the $_SESSION array itself (and not a member array) is the same. Why do you think that using it on a $_SESSION array or $_SESSION itself would give you something different?

PS - What is this "REQUEST" item that you mention?  It is not an automatic entry that I know of.  

Edited by ginerjm

What are you looking to accomplish? Are you writing a script that processes all the information in the $_SESSION array and/or presumably the $_REQUEST array? If so, would using something like the foreach loop work for your project? That would allow you to process everything without destroying the original array.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.