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

  • SEARCH
  • Home
  • 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 6662769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:25:33+00:00 2026-05-26T02:25:33+00:00

I have two multidimensional arrays like: [a] [b] [c] and [a] [b] [c] [d]

  • 0

I have two multidimensional arrays like:

[a]
  [b]
    [c]             

and

[a]
  [b]
    [c]
    [d]

and want to turn it into a single array

[a]
  [b]
    [c]
    [d]

I tried the array_merge_recursive() function, but it creates new elements on the last level instead of overwriting them.

For example, if [c] is "X" in the first array, and "Y" in the second array, I get array("X", "Y") instead of the last value ("Y").

  • 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-26T02:25:34+00:00Added an answer on May 26, 2026 at 2:25 am

    Is this what you’re after, using array_replace_recursive?

    <?php
    
    $arr1 = array ('a' => array ('b' => array ('c' => 'X'), 'd' => 'array_1_d'));
    $arr2 = array ('a' => array ('b' => array ('c' => 'Y', 'd' => 'Z')), 'e' => 'array_2_e');
    
    $arr3 = array_replace_recursive ($arr1, $arr2);
    
    var_dump($arr3);
    

    Outputs:

    array(2) {
      ["a"]=>
      array(2) {
        ["b"]=>
        array(2) {
          ["c"]=>
          string(1) "Y"
          ["d"]=>
          string(1) "Z"
        }
        ["d"]=>
        string(9) "array_1_d"
      }
      ["e"]=>
      string(9) "array_2_e"
    }
    

    http://www.php.net/manual/en/function.array-replace-recursive.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two questions regarding the multidimensional arrays. I declared a 3D array using
I have a problem.. i want to combine two array.. multidimensional Array 1. Array
I have a string like this: $string = 'one/two/three/four'; which I turn it into
I have a multidimensional array which I would like to sort by two factors:
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have a multidimensional-array which looks like this: $array = ( [0] => array
I have a two dimensional array like this $FrstArr = Array( [0]= array( [0]=>101,
I have an single-dimensional array of PHP objects. Each object has two attributes, one
Sure, you can have nested lists to represent multidimensional arrays, but that seems costly...

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.