Jump to content

Help with sending an array variable from page to page


Recommended Posts

I've heard to accomplish sending array variables from page to page in PHP, you need to use serialize() and unserialize().  Is this try?  Here's my example.


Imagine in one page I generate an array $names[].  It contains a list of names obviously.  How do I use serialize() and unserialize() to pass this array from page to page so I can later use a loop to display each element of the array?



Link to comment
Share on other sites

$serialized = serialize($names);
$unserialized = unserialize($serialized);


Another option would be storing the _POST values:

$_SESSION['_POST'] = array_merge($_SESSION['_POST'], $_POST);//merges the new _POST with the already existing values. Note: if key exist in _SESSION[_POST] it will be overwritten

Link to comment
Share on other sites

Yes, that is a good way to store arrays (if you only need the array as is) although you will still need to find a way to pass the variable between the pages. Either by posting a form, saving it in a session or cookie or storing it in a text file or a database. Which alternative you would want to use depends on the situation of course.

Link to comment
Share on other sites

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.

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.