Darkmatter5 Posted July 24, 2009 Share Posted July 24, 2009 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? Thanks! Link to comment https://forums.phpfreaks.com/topic/167323-help-with-sending-an-array-variable-from-page-to-page/ Share on other sites More sharing options...
ignace Posted July 24, 2009 Share Posted July 24, 2009 $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 https://forums.phpfreaks.com/topic/167323-help-with-sending-an-array-variable-from-page-to-page/#findComment-882264 Share on other sites More sharing options...
vineld Posted July 24, 2009 Share Posted July 24, 2009 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 https://forums.phpfreaks.com/topic/167323-help-with-sending-an-array-variable-from-page-to-page/#findComment-882268 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.