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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:04:11+00:00 2026-05-17T00:04:11+00:00

Example: $arr1 = array(‘a’ => "1", ‘b’ => "2", ‘c’ => "3", ‘z’ =>

  • 0

Example:

$arr1 = array('a' => "1", 'b' => "2", 'c' => "3", 'z' => "4");
$arr2 = array('a' => "9", 'b' => "8", 'c' => "7", 'd' => "6", 'e' => "5");

Output:

$result = array(
    'a' => array( 'f1' => "1", 'f2' => "9"),
    'b' => array( 'f1' => "2", 'f2' => "8"),
    'c' => array( 'f1' => "3", 'f2' => "7"),
    'd' => array( 'f1' => "0", 'f2' => "6"),
    'e' => array( 'f1' => "0", 'f2' => "5"),
    'z' => array( 'f1' => "4", 'f2' => "0"),
);

The size of $arr1 can be ‘>’, ‘<‘ or ‘=’ size of $arr2

  • 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-17T00:04:12+00:00Added an answer on May 17, 2026 at 12:04 am

    I think this it,

    $arr1 = array('a' => "1", 'b' => "2", 'c' => "3", 'z' => "4");
    
    $arr2 = array('a' => "9", 'b' => "8", 'c' => "7", 'd' => "6", 'e' => "5");
    
    
    foreach($arr1 as $key => $value){
        $a[$key]['f1'] = $value;
    }
    
    foreach($arr2 as $key => $value){
        $b[$key]['f2'] = $value;
    }
    
    $c = array_merge_recursive($a, $b);
    foreach($c as $key => $value){
        $result[$key]['f1'] = (array_key_exists('f1', $value)) ? $value['f1']: 0;
        $result[$key]['f2'] = (array_key_exists('f2', $value)) ? $value['f2']: 0;
    }
    
    echo "<pre>".print_r ($result, true);
    

    the output:

    Array
    (
        [a] => Array
            (
                [f1] => 1
                [f2] => 9
            )
    
        [b] => Array
            (
                [f1] => 2
                [f2] => 8
            )
    
        [c] => Array
            (
                [f1] => 3
                [f2] => 7
            )
    
        [z] => Array
            (
                [f1] => 4
                [f2] => 0
            )
    
        [d] => Array
            (
                [f1] => 0
                [f2] => 6
            )
    
        [e] => Array
            (
                [f1] => 0
                [f2] => 5
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example I have: array[3] arr1 = {.5,.5,0} array[3] arr2 = {.5,0,.5} array[3] arr3
Example: var arr_1:Array = new Array(); arr_1.push({sdate:2010-02-02,status:New}); arr_1.push({sdate:2010-02-03,status:New}); arr_1.push({sdate:2010-02-04,status:New}); arr_1.push({sdate:2010-02-05,status:New}); How can i change
Example output from PHP: { RootName_0:{Id:1,ValId:1,Value:Colour,Text:Blue}, RootName_1:{Id:1,ValId:2,Value:Colour,Text:Red} } How can I use Backbone.js or
I have two matrices in MATLAB lets say arr1 and arr2 of size 1000*1000
Example code 1: const int N=100000; for(int j=0;j<N;j++){ arr1[j] += a1[j]; arr2[j] += a2[j];
Example: an Employee table with an optional DateOfBirth field can be normalized into two
I can visualize the situation when, for example, I have allocated memory in the
I have an array from ten (or more) numbers, for example: arr[1,2,3,4,5,6,7,8,9,10] I want
I need to be able to mirror a multidimensional array that changes in size.
I'm trying to put an array in the order of another array. For example,

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.