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 7439221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:40:29+00:00 2026-05-29T10:40:29+00:00

I have the following two arrays: Array ( [Jonah] => 27 [Bianca] => 32

  • 0

I have the following two arrays:

Array ( [Jonah] => 27 [Bianca] => 32

Array ( [Jonah] => 2 [Bianca] => 7

Is it possible to merge them together to form a multidimensional array in this format?

Array ( [0] => Array 
               ( [name] => Jonah 
                 [age] => 27 
                 [number] => 2 )
        [1] => Array 
               ( [name] => Bianca 
                 [age] => 32 
                 [number] => 7 )
      )
  • 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-29T10:40:29+00:00Added an answer on May 29, 2026 at 10:40 am

    A temporary array keyed by name stores the values from the first two arrays. The temporary array is then copied to a final array keyed numerically:

    $arr1 = array ( 'Jonah' => 27, 'Bianca' => 32 );
    $arr2 = array ( 'Jonah' => 2, 'Bianca' => 7 );
    
    $tmp = array();
    
    // Using the first array, create array keys to $tmp based on
    // the name, and holding the age...
    foreach ($arr1 as $name => $age) {
     $tmp[$name] = array('name' => $name, 'age' => $age);
    }
    
    // Then add the number from the second array
    // to the array identified by $name inside $tmp
    foreach ($arr2 as $name => $num) {
      $tmp[$name]['number'] = $num;
    }
    
    // Final array indexed numerically:
    $output = array_values($tmp);
    print_r($output);
    
    Array
    (
        [0] => Array
            (
                [name] => Jonah
                [age] => 27
                [number] => 2
            )
    
        [1] => Array
            (
                [name] => Bianca
                [age] => 32
                [number] => 7
            )
    
    )
    

    Note: The last step of copying the array to make it numerically isn’t strictly needed, if you’re ok with your output array being keyed by name. In that case, $tmp is the final product.

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

Sidebar

Related Questions

I have a two-dimensional array. When I print/dump this I get the following My
I have following two arrays and the code to find array_diff: $obs_ws = array(you,
I have two arrays with following structure: $arr1 = array( array( name => name1,
I currently have two arrays that look like this: Swatches: Array ( [0] =>
I have two identical byte arrays in the following segment of code: /// <summary>
I have two arrays arr1 = new Array(); arr2 = new Array(); If i
I have two sets of arrays like this for example. $Arr1['uid'][]='user 1'; $Arr1['weight'][]=1; $Arr1['uid'][]='user
I have two associative arrays in PHP that are defined as following: $this_week[] =
I have two arrays, each containing strings. The first array is a list of
I have this two array $array1 = Array ( [0] => 5 [1] =>

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.