Merging stdClass() objects in php

Merging stdClass() objects in php

Popular content

Donate to Us


Donate by clicking Ads :)

Who's online

There are currently 0 users and 16 guests online.

Merging stdClass() objects in php


<?php
 
$foo1 = new stdClass();
$foo2 = new stdClass();
$foo3 = new stdClass();
 
$foo1->one = "1";
$foo2->two = "2";
 
foreach ( $foo1 as $key => $value ) {
  $foo3->$key = $value;
}
 
foreach ( $foo2 as $key => $value ) {
  $foo3->$key = $value;
}
 
var_dump($foo3);

Share/Save
10
Average: 10 (3 votes)
Your rating: None
Tags
Comments

A good one.
Thanks for the info.

Post new comment

 
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.