I use an API that returns me to an email address given an array like this:
stdClass Object
(
[status] => OK
[contact] => stdClass Object
(
[id] => 0000000
[email] => [email protected]
[last_activity] => 1362131446
[last_update] => 0
[created_at] => 1356617740
[sent] => 5
[open] => 1
[click] => 1
[spam] => 0
[bounce] => 0
[blocked] => 0
[queued] => 0
)
[lists] => Array
(
[0] => stdClass Object
(
[active] => 1
[unsub] => 1
[unsub_at] => 1363078528
)
)
)
how to merge info [contact] with [lists] [0] in a single object?
Thank you for your help
Approach 1: Convert object into data array and merge them using array_merge() function and convert this merged array back into object of class stdClass. Note: While merging the objects using array_merge(), elements of array in argument1 are overwritten by elements of array in argument2.
You could simply use array_merge(firstObject,secondObject) function.
$info = yourstuff;
$arrContact = (array) $info->contact;
$arrList = (array) $info->lists[0];
$merged = array_merge($arrContact, $arrList);
var_dump($merged, 'have fun');
Quite trivial ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With