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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:01:41+00:00 2026-06-06T08:01:41+00:00

Good day! I am having errors in merging/combining/concatenating arrays. For example I have arrays,

  • 0

Good day! I am having errors in merging/combining/concatenating arrays.

For example I have arrays,

$array1 [] = array(
'var1' => $var1,
'var2' => $var2,
'var3' => $var3,
);
$array2 [] = array(
'var4' => $var4,
'var5' => $var5,
'var6' => $var6,
);

Those arrays have multiple records inside of them but have the same number of records.
When i var_dump them the structure looks like this:

//array1
array(3){
    [0]=>array(3){
        ["var1"]=> string (4) "var1"
        ["var2"]=> string (4) "var2"
        ["var3"]=> string (4) "var3"
    }
    [1]=>array(3){
        ["var1"]=> string (4) "var1"
        ["var2"]=> string (4) "var2"
        ["var3"]=> string (4) "var3"
    }
    [2]=>array(3){
        ["var1"]=> string (4) "var1"
        ["var2"]=> string (4) "var2"
        ["var3"]=> string (4) "var3"
    }
}
//array2
array(3){
    [0]=>array(3){
        ["var4"]=> string (4) "var4"
        ["var5"]=> string (4) "var5"
        ["var6"]=> string (4) "var6"
    }
    [1]=>array(3){
        ["var4"]=> string (4) "var4"
        ["var5"]=> string (4) "var5"
        ["var6"]=> string (4) "var6"
    }
    [2]=>array(3){
        ["var4"]=> string (4) "var4"
        ["var5"]=> string (4) "var5"
        ["var6"]=> string (4) "var6"
    }
}

I want to add both arrays

$array_combined [] = array(
'var1' => $var1,
'var2' => $var2,
'var3' => $var3,
'var4' => $var4,
'var5' => $var5,
'var6' => $var6,
);

I think the structure should look like this when var_dump(ed):

//array_combined
array(3){
    [0]=>array(6){
        ["var1"]=> string (4) "var1"
        ["var2"]=> string (4) "var2"
        ["var3"]=> string (4) "var3"
        ["var4"]=> string (4) "var4"
        ["var5"]=> string (4) "var5"
        ["var6"]=> string (4) "var6"

    }
    [1]=>array(3){
        ["var1"]=> string (4) "var1"
        ["var2"]=> string (4) "var2"
        ["var3"]=> string (4) "var3"
        ["var4"]=> string (4) "var4"
        ["var5"]=> string (4) "var5"
        ["var6"]=> string (4) "var6"

    }
    [2]=>array(3){
        ["var1"]=> string (4) "var1"
        ["var2"]=> string (4) "var2"
        ["var3"]=> string (4) "var3"
        ["var4"]=> string (4) "var4"
        ["var5"]=> string (4) "var5"
        ["var6"]=> string (4) "var6"
    }
}

I tried:

 $array_combine = array_combine($array1, $array2);
 $array_merge = array_merge($array1, $array2);
 $array_merge_recursive = array_merge_recursive($array1, $array2);

but i keep getting this error:

Notice: Undefined index: cmax in D:\xampp\htdocs\vra\GetVM – Copy.php on line 365

The code that i posted there is just similar to my real code.
Line 365 contains echo ( $record[‘var4’] ).
I was doing something like this to output the combined/merged array.

$array_merge = merge_array($array1, $array2)
foreach ( $array_merge as $record ) {
echo ( $record['var1'] );
echo ( $record['var2'] );
echo ( $record['var3'] );
echo ( $record['var4'] );//this is were the error occurs
echo ( $record['var5'] );//same error here
echo ( $record['var6'] );//same error here
}

Tried using array_combine(),array_merge_recursive and $combined_array = $array1 + $array2

  • 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-06-06T08:01:45+00:00Added an answer on June 6, 2026 at 8:01 am

    I’d say the issue is stemming from you using multidimensional arrays and trying to combine them as single dimension arrays.

    Instead of

    $array_merge = array_merge($array1, $array2);
    

    Try

    $array_merge[0] = array_merge($array1[0], $array2[0]);
    $array_merge[1] = array_merge($array1[1], $array2[1]);
    $array_merge[2] = array_merge($array1[2], $array2[2]);
    [ ... ]
    

    If you want to strictly combine them and never overright values from the first with the second, use

    $array_merge = $array1 + $array2;
    

    Some additional notes on array merging can be found at php.net

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

Sidebar

Related Questions

Good day everyone. I have been having the same problem all day at work
Good day, I am having an interesting problem that I cannot understand. I have
hope you're having a good day. I have been programming a IRC chatbot in
Good day. I'm new to jQuery, and have a passing familiarity with javascript, having
Good day, I have a class that implements the LoaderCallbacks, and hence have the
Good day I have a custom TextBox that has a IndicatorTextBox.ui.xml file as well
Good day, I have like 15 images I need to be buttons. I have
Good afternoon ladies and gents. So, it is not my day for errors. Implementing
Good day, I am having an issue trying to get the Text on a
Good day all; I have an UIImageView that I animate around a large UIView.

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.