[DW - solved!!]Quick Question About Merging Arrays
Posted: Wed Sep 09, 2009 10:06 am
Ok,
So basically, for my template class I can assign variables right? yeah. These variables are held in the private property $vars. Now, the assign_vars() function basically consists of this:But, it appears that old values are not overwritten with new ones when assigning variables that have already been assigned.
I've had a poke in the manual, and found that array_merge() (or += for arrays) does not overwrite pre-existing array keys with new values.
So, short of putting the whole thing into a foreach() loop and assigning the variables one by one, is there any way to force array_merge() (or +=) to overwrite existing array keys with new values??
Any help appreciated
Thanks,
Jack.
So basically, for my template class I can assign variables right? yeah. These variables are held in the private property $vars. Now, the assign_vars() function basically consists of this:
Code: Select all
$this->vars += $vars; //$vars being the argument passed. it's basically the same as $this->vars = array_merge($this->vars, $vars);I've had a poke in the manual, and found that array_merge() (or += for arrays) does not overwrite pre-existing array keys with new values.
So, short of putting the whole thing into a foreach() loop and assigning the variables one by one, is there any way to force array_merge() (or +=) to overwrite existing array keys with new values??
Any help appreciated
Thanks,
Jack.