Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 804599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:56:44+00:00 2026-05-14T23:56:44+00:00

If I have the following arrays arry1 = array( 101 => array( ‘title1’ =>

  • 0

If I have the following arrays

arry1 = array(
    101 => array(
        'title1' => 'data', 
        'title2' => 'data', 
        'title3' => 'data'
    ),
    102 => array(
        'title1' => 'data', 
        'title2' => 'data', 
        'title3' => 'data'
    ),
    .
    .
    .
);

arry2 = array(
    101 => array(
        'title4' => 'data', 
        'title5' => 'data', 
        'title6' => 'data'
    ),
    102 => array(
        'title4' => 'data', 
        'title5' => 'data', 
        'title6' => 'data'
    ),
    .
    .
    .
);

and I want to change them into

arry3 = array(
    101 => array(
        'title1' => 'data', 
        'title2' => 'data', 
        'title3' => 'data',
        'title4' => 'data', 
        'title5' => 'data', 
        'title6' => 'data'
    ),
    102 => array(
        'title1' => 'data', 
        'title2' => 'data', 
        'title3' => 'data',
        'title4' => 'data', 
        'title5' => 'data', 
        'title6' => 'data'
    ),
    .
    .
    .
);

Is there a simple function from php arrays to do this? If not, what do you believe would be the most efficient way to program this?

Thanks for any help,
Metropolis

EDITED

Sorry I updated the arrays to be the way they actually should be….array_merge_recursive gives me the following,

arry3 = array(
    0 => array(
        'title1' => 'data', 
        'title2' => 'data', 
        'title3' => 'data'
    ),
    1 => array(
        'title4' => 'data', 
        'title5' => 'data', 
        'title6' => 'data'
    ),
    .
    .
    .
);

I need the 101, and 102 to stick, and I need the data to all be in the same lower level array….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:56:45+00:00Added an answer on May 14, 2026 at 11:56 pm

    I assume you want to add the latter array to the first. Therefore, use this:

    array_merge_recursive(array1, array2);
    

    … and it’ll do exactly what you want.

    EDIT:
    As it seems, that my above solution is not entirely correct, use this:

    <?
    
    function array_merge_subarrays(array $array1, array $array2) {
        $resultArray = array();
        // The foreach instead of a plain for is to keep the specific values of the keys
        foreach ($array1 as $key => $subarray) {
            $resultArray[$key] = array_merge($subarray, $array2[$key]);
        }
        return $resultArray;
    }
    
    $arr1 = array(
        101 => array(
            'title1' => 'data', 
            'title2' => 'data', 
            'title3' => 'data'
        ),
        102 => array(
            'title1' => 'data', 
            'title2' => 'data', 
            'title3' => 'data'
        )
    );
    
    $arr2 = array(
        101 => array(
            'title4' => 'data', 
            'title5' => 'data', 
            'title6' => 'data'
        ),
        102 => array(
            'title4' => 'data', 
            'title5' => 'data', 
            'title6' => 'data'
        )
    );
    
    print_r(array_merge_subarrays($arr1, $arr2));
    
    /*
    
    OUTPUTS:
    
    Array ( 
        [101] => Array ( 
            [title1] => data
            [title2] => data
            [title3] => data
            [title4] => data
            [title5] => data
            [title6] => data
        )
        [102] => Array (
            [title1] => data 
            [title2] => data 
            [title3] => data 
            [title4] => data 
            [title5] => data 
            [title6] => data
        )
    )
    
    */
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 394k
  • Answers 394k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is definitely dicey from a security perspective. Anyone who… May 15, 2026 at 2:23 am
  • Editorial Team
    Editorial Team added an answer Use is_callable to determine whether a given variable is a… May 15, 2026 at 2:23 am
  • Editorial Team
    Editorial Team added an answer EDIT: After more consideration and some discussion in the comments,… May 15, 2026 at 2:23 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.