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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:43:38+00:00 2026-06-02T03:43:38+00:00

is it possible to merge 2 arrays without overlapping the same keys ? I

  • 0

is it possible to merge 2 arrays without overlapping the same keys ?

I want it to add a new item if a key already exists.

Like that

$a = array(1,2,3,4);
$b = array(3,4,5,6);
merge $a and $b 

desired result is

array(1,2,3,4,3,4,5,6) 
  • 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-02T03:43:39+00:00Added an answer on June 2, 2026 at 3:43 am

    Use array_merge

    $a = array(1,2,3,4);
    $b = array(3,4,5,6);
    $c = array_merge($a,$b);
    print_r($c);
    

    Working example here

    This is the key phrase from the help :

    If the input arrays have the same string keys, then the later value
    for that key will overwrite the previous one. If, however, the arrays
    contain numeric keys, the later value will not overwrite the original
    value, but will be appended.

    So this will only work when you have numeric keys

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

Sidebar

Related Questions

Possible Duplicate: Merge 2 Arrays and Sum the Values (Numeric Keys) I have two
Possible Duplicate: Combine Two Arrays with numerical keys without overwriting the old keys OK
Possible Duplicate: How can I merge two MySql tables? I want to merge multiple
i need to merge an 2d array, if possible without any loops. Is there
Possible Duplicates: Merging two sorted lists Algorithm for N-way merge Given k sorted arrays
Possible Duplicate: Merge two lists in python? How can I prepend list elements into
Is it possible to merge the two videos by c# asp.net with the help
Is it possible to merge a range of revisions from one branch to another
Is it possible to merge changes from a central repo to a local branch
Is it possible to merge two JSON documents with the Jackson JSON library? I

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.