I have 2 arrays stored serialized in my database, when individually unzerialized they might output:
array(1 => 0,
2 => 1,
3 => 4,
4 => 0,
5 => 2);
array(2 => 3,
4 => 1);
I need to merge them in such a way that the values of the 2nd array override those in the 1st, but also preserve any values in array 1 that are not in array 2 for example the ideal output of the 2 combined would be:
array(1 => 0,
2 => 3,
3 => 4,
4 => 1,
5 => 2);
When I attempt to combine them I get the error:
Fatal error: Unsupported operand types
This is how I have tried (ref: Combine two arrays):
$array1 = unserialize($row['serialized1']);
$array2 = unserialize($row['serialized2']);
$_SESSION['combined_array'] = $array1+$array2;
Also:
$_SESSION['combined_array'] = unserialize($row['serialized2'])+unserialize($row['serialized1']);
Edit:
I have also tried:
$_SESSION['combined_array'] = array_merge($array1,$array2);
This does not error, but does not result in any combined array.
Thank you for any pointers.