Answers for "php merge object arrays"

PHP
2

merge two objects in php

array_merge((array)json_decode($data1), (array) json_decode($data2));
Posted by: Guest on April-26-2020
0

php concat objects

// 1) Copy over the attributes of $obj1 to $obj2:

foreach ( $obj1 as $attr => $value ) {
	$obj2->{$attr} = $value;
}

// 2) Cast the objects to arrays, merge those arrays, then cast 
// the resulting array back to a stdClass object.

$merged = (object) array_merge((array) $obj1, (array) $obj2);
Posted by: Guest on February-17-2022

Browse Popular Code Answers by Language