merge array but force overwrite

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
denz
Forum Newbie
Posts: 18
Joined: Fri Jun 24, 2005 4:18 pm

merge array but force overwrite

Post by denz »

Hi All,

a little stumped here!

I have a page of options on a from which are dynamically created from the DB, so i've no idea how many options will be passed to the next page, could 1 or 100.
On the following page i need to convert the $_POST in to a Session variable, to anaylse it and remember it for other pages, but i've tried using

Code: Select all

array_merge()
like this:

Code: Select all

$_SESSION = array_merge($_SESSION, $_POST);

which works a treat the first time a user moves to the second page, but if they go back and change their mind (which they probably will) i need to pull the new $_POST vars into the session varialbes. However, the array_merge fucntion only appends, i need to remove items which weren't in the $_POST.

Any ideas how to do this? (if of course i've explained myself properly! ) :D

Thanks
denz
Forum Newbie
Posts: 18
Joined: Fri Jun 24, 2005 4:18 pm

Post by denz »

worked it out!

Code: Select all

$add_serv = mysql_query("select * from add_serv");
			while ($add_serv_r = mysql_fetch_assoc($add_serv))	
						{
$_SESSION[$add_serv_r['serv_code']] = null;
	}
put this at the bottom of the page which gernates the form, so when passed to the next page the session vars are set only to the vars that are selected!

hurrah! 8)
Post Reply