-3

I have one object having an array like

object(ElggObject)[1023]
  protected 'attributes' => 
    array
      'guid' => string '39344' (length=5)
      'type' => string 'object' (length=6)
      'subtype' => string '25' (length=2)
      'owner_guid' => string '39136' (length=5)
      'container_guid' => string '39136' (length=5)
      'site_guid' => string '1' (length=1)
      'access_id' => string '2' (length=1)
      'time_created' => string '1359536708' (length=10)
      'time_updated' => string '1359536708' (length=10)
      'last_action' => string '1359536708' (length=10)
      'enabled' => string 'yes' (length=3)
      'tables_split' => int 2
      'tables_loaded' => int 2
      'title' => string 'Community developer 5' (length=21)
      'description' => string '<p>$entity = get_entity($entity_guid);</p>' (length=42)
  protected 'url_override' => null
  protected 'icon_override' => null
  protected 'temp_metadata' => 
    array
      empty.........

The above one only one object. And another array having an array of obejcts like below. So i need to merge two things..

array
  0 => 
    object(ElggObject)[1031]
      protected 'attributes' => 
        array
          'guid' => string '35116' (length=5)
          'type' => string 'object' (length=6)
          'subtype' => string '25' (length=2)
          'owner_guid' => string '2' (length=1)
          'container_guid' => string '2' (length=1)
          'site_guid' => string '1' (length=1)
          'access_id' => string '2' (length=1)
          'time_created' => string '1322222868' (length=10)
          'time_updated' => string '1402048391' (length=10)
          'last_action' => string '1322222868' (length=10)
          'enabled' => string 'yes' (length=3)
          'tables_split' => int 2
          'tables_loaded' => int 2
          'title' => string 'Developer for Ramco Systems' (length=27)
          'description' => string '<ul>

  1 => 
    object(ElggObject)[1034]
      protected 'attributes' => 
        array
          'guid' => string '39339' (length=5)
          'type' => string 'object' (length=6)
          'subtype' => string '25' (length=2)
          'owner_guid' => string '39136' (length=5)
          'container_guid' => string '39136' (length=5)
          'site_guid' => string '1' (length=1)
          'access_id' => string '2' (length=1)
          'time_created' => string '1359535318' (length=10)
          'time_updated' => string '1402032776' (length=10)
          'last_action' => string '1359535318' (length=10)
          'enabled' => string 'yes' (length=3)
          'tables_split' => int 2
          'tables_loaded' => int 2
          'title' => string 'Community developer 2' (length=21)
          'description' => string '<p>Job description jkjkhjkhk</p>' (length=32)

  2 => 
    object(ElggObject)[1037]
      protected 'attributes' => 
        array
          'guid' => string '39342' (length=5)
          'type' => string 'object' (length=6)
          'subtype' => string '25' (length=2)
          'owner_guid' => string '39136' (length=5)
          'container_guid' => string '39136' (length=5)
          'site_guid' => string '1' (length=1)
          'access_id' => string '2' (length=1)
          'time_created' => string '1359536322' (length=10)
          'time_updated' => string '1401962732' (length=10)
          'last_action' => string '1359536322' (length=10)
          'enabled' => string 'yes' (length=3)
          'tables_split' => int 2
          'tables_loaded' => int 2
          'title' => string 'Community developer 4' (length=21)

So how to merge two things...i tried array_merge but didn't worked for me ...

Any suggestion..

UI Dev
  • 689
  • 2
  • 9
  • 31

3 Answers3

2

Try this one :

$result = (object)array_merge((array)$obj1, (array)$obj2);
Naveed Ramzan
  • 3,565
  • 3
  • 25
  • 30
0

Edited:

$secondArray[] = $firstArrayObj;

Try this one. I hope this works.

Sreenath
  • 480
  • 2
  • 6
  • 17
0

You can use array_merge_recursive function in PHP to merge multidimensional array.

For example,

$ar1 = array("color" => array("favorite" => "red"), 5);
$ar2 = array("color1" => array("favorite" => "green", "blue"));
$result = array_merge_recursive($ar1, $ar2);
print_r($result);

The important thing is Key should be different. If key is unique the values will be merged from different array having same key.

Nithyanandhan M
  • 1,524
  • 1
  • 16
  • 26