title: php push children array into the parent array
body: <p>I am getting data and trying to push <code>children</code> data into his parent array but not getting proper index in the array.</p>
  
  <pre><code>Array
  (
      [0] =&gt; stdClass Object
          (
              [id] =&gt; 708
              [user_id] =&gt; 104
              [component] =&gt; activity
              [type] =&gt; activity_comment
              [action] =&gt; XXXX XXXX posted a new activity comment
              [content] =&gt; hello manan
              [primary_link] =&gt; 
              [item_id] =&gt; 707
              [secondary_item_id] =&gt; 707
              [date_recorded] =&gt; 2018-02-19 05:01:16
              [hide_sitewide] =&gt; 0
              [mptt_left] =&gt; 2
              [mptt_right] =&gt; 5
              [is_spam] =&gt; 0
              [user_email] =&gt; xxxxxxx@xxxxx.xxx
              [user_nicename] =&gt; manan88
              [user_login] =&gt; manan88
              [display_name] =&gt; XXXX XXXX
              [user_fullname] =&gt; XXXX XXXX
              [children] =&gt; Array
                  (
                      [710] =&gt; stdClass Object
                          (
                              [id] =&gt; 710
                              [user_id] =&gt; 104
                              [component] =&gt; activity
                              [type] =&gt; activity_comment
                              [action] =&gt; XXXX XXXX posted a new activity comment
                              [content] =&gt; hey
                              [primary_link] =&gt; 
                              [item_id] =&gt; 707
                              [secondary_item_id] =&gt; 708
                              [date_recorded] =&gt; 2018-02-19 05:02:10
                              [hide_sitewide] =&gt; 0
                              [mptt_left] =&gt; 3
                              [mptt_right] =&gt; 4
                              [is_spam] =&gt; 0
                              [user_email] =&gt; xxxxxxx@xxxxx.xxx
                              [user_nicename] =&gt; manan88
                              [user_login] =&gt; manan88
                              [display_name] =&gt; XXXX XXXX
                              [user_fullname] =&gt; XXXX XXXX
                              [children] =&gt; Array
                                  (
                                  )
  
                              [depth] =&gt; 2
                          )
  
                  )
  
              [depth] =&gt; 1
          )
  
      [1] =&gt; stdClass Object
          (
              [id] =&gt; 709
              [user_id] =&gt; 104
              [component] =&gt; activity
              [type] =&gt; activity_comment
              [action] =&gt; XXXX XXXX posted a new activity comment
              [content] =&gt; hello manan 2
              [primary_link] =&gt; 
              [item_id] =&gt; 707
              [secondary_item_id] =&gt; 707
              [date_recorded] =&gt; 2018-02-19 05:01:38
              [hide_sitewide] =&gt; 0
              [mptt_left] =&gt; 6
              [mptt_right] =&gt; 7
              [is_spam] =&gt; 0
              [user_email] =&gt; xxxxxxx@xxxxx.xxx
              [user_nicename] =&gt; manan88
              [user_login] =&gt; manan88
              [display_name] =&gt; XXXX XXXX
              [user_fullname] =&gt; XXXX XXXX
              [children] =&gt; Array
                  (
                  )
  
              [depth] =&gt; 1
          )
  
  )
  </code></pre>
  
  <p>but I want to merge all child values back into the parent array like this:</p>
  
  <pre><code>Array
  (
      [0] =&gt; stdClass Object
          (
              [id] =&gt; 708
              [user_id] =&gt; 104
              [component] =&gt; activity
              [type] =&gt; activity_comment
              [action] =&gt; XXXX XXXX posted a new activity comment
              [content] =&gt; hello manan
              [primary_link] =&gt; 
              [item_id] =&gt; 707
              [secondary_item_id] =&gt; 707
              [date_recorded] =&gt; 2018-02-19 05:01:16
              [hide_sitewide] =&gt; 0
              [mptt_left] =&gt; 2
              [mptt_right] =&gt; 5
              [is_spam] =&gt; 0
              [user_email] =&gt; xxxxxxx@xxxxx.xxx
              [user_nicename] =&gt; manan88
              [user_login] =&gt; manan88
              [display_name] =&gt; XXXX XXXX
              [user_fullname] =&gt; XXXX XXXX
              [children] =&gt; Array
                  (
                      [710] =&gt; stdClass Object
                          (
                              [id] =&gt; 710
                              [user_id] =&gt; 104
                              [component] =&gt; activity
                              [type] =&gt; activity_comment
                              [action] =&gt; XXXX XXXX posted a new activity comment
                              [content] =&gt; hey
                              [primary_link] =&gt; 
                              [item_id] =&gt; 707
                              [secondary_item_id] =&gt; 708
                              [date_recorded] =&gt; 2018-02-19 05:02:10
                              [hide_sitewide] =&gt; 0
                              [mptt_left] =&gt; 3
                              [mptt_right] =&gt; 4
                              [is_spam] =&gt; 0
                              [user_email] =&gt; xxxxxxx@xxxxx.xxx
                              [user_nicename] =&gt; manan88
                              [user_login] =&gt; manan88
                              [display_name] =&gt; XXXX XXXX
                              [user_fullname] =&gt; XXXX XXXX
                              [children] =&gt; Array
                                  (
                                  )
  
                              [depth] =&gt; 2
                          )
  
                  )
  
              [depth] =&gt; 1
          )
      [1] =&gt; stdClass Object
          (
              [id] =&gt; 710
              [user_id] =&gt; 104
              [component] =&gt; activity
              [type] =&gt; activity_comment
              [action] =&gt; XXXX XXXX posted a new activity comment
              [content] =&gt; hey
              [primary_link] =&gt; 
              [item_id] =&gt; 707
              [secondary_item_id] =&gt; 708
              [date_recorded] =&gt; 2018-02-19 05:02:10
              [hide_sitewide] =&gt; 0
              [mptt_left] =&gt; 3
              [mptt_right] =&gt; 4
              [is_spam] =&gt; 0
              [user_email] =&gt; xxxxxxx@xxxxx.xxx
              [user_nicename] =&gt; manan88
              [user_login] =&gt; manan88
              [display_name] =&gt; XXXX XXXX
              [user_fullname] =&gt; XXXX XXXX
              [children] =&gt; Array
                  (
                  )
  
              [depth] =&gt; 2
          )
      [2] =&gt; stdClass Object
          (
              [id] =&gt; 709
              [user_id] =&gt; 104
              [component] =&gt; activity
              [type] =&gt; activity_comment
              [action] =&gt; XXXX XXXX posted a new activity comment
              [content] =&gt; hello manan 2
              [primary_link] =&gt; 
              [item_id] =&gt; 707
              [secondary_item_id] =&gt; 707
              [date_recorded] =&gt; 2018-02-19 05:01:38
              [hide_sitewide] =&gt; 0
              [mptt_left] =&gt; 6
              [mptt_right] =&gt; 7
              [is_spam] =&gt; 0
              [user_email] =&gt; xxxxxxx@xxxxx.xxx
              [user_nicename] =&gt; manan88
              [user_login] =&gt; manan88
              [display_name] =&gt; XXXX XXXX
              [user_fullname] =&gt; XXXX XXXX
              [children] =&gt; Array
                  (
                  )
  
              [depth] =&gt; 1
          )
  
  )
  </code></pre>
  
  <p>I have tried with <code>array_push</code> and after that, I have used <code>array_multisort</code> not working. Any idea about this.</p>
  
  <pre><code>for ($i=0; $i&lt;count($data); $i++) {
      // Move children to main array
      $children = $data[$i]-&gt;children;
      if (!empty($children)) {
          foreach ($children as $key =&gt; $value) {
              array_push($data, $children[$key]);
          }
      }
  }
  
  if (!empty($data)) {
      array_multisort($data, SORT_ASC);
  }
  </code></pre>