Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #php #concat #objects
ADD COMMENT
Topic
Name
4+4 =