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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:51:03+00:00 2026-05-27T19:51:03+00:00

After I’ve asked for a method to combine 2 arrays I got several answers

  • 0

After I’ve asked for a method to combine 2 arrays I got several answers as you can find here:

Array combine into associative array

I’ve implemented the accepted answer but, as the author warned, I’ve run into a “duplicate keys” problem.

This is the code I’m using:

$a = array(4=>3,5=>3);
$b = array(array(0=>0,1=>4,2=>10,3=>1000),
           array(0=>0,1=>40,2=>100,3=>2000),
           array(4=>10)
          );

$c = array();
foreach($b as $tmp) {
    $c[] = $a+$tmp;
}

var_dump($c);

But it returns an array like this one:

Array (
    [0] => Array (
        [3] => 1 
        [5] => 1 
        [6] => 0 
        [7] => 0 
        [8] => 0
        )
    [1] => Array (
        [3] => 1 
        [5] => 1 
        [6] => 0 
        [7] => 0 
        [8] => 0
        ) 
    [2] => Array (
        [3] => 1 
        [5] => 1 
        [6] => 1 
        [7] => 0 
        [8] => 0
        )
    [3] => Array ( 
        [3] => 1 
        [5] => 1 
        [6] => 1 
        [7] => 0 
        [8] => 0
        )
    [4] =>...

As you can see the key 0 is the same as key 1.. etc.

How can I solve this?

Thanks in advance.

  • 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-27T19:51:03+00:00Added an answer on May 27, 2026 at 7:51 pm

    Sorry, my original answer displayed a complete lack of reading comprehension skills. If I correctly understand what you’re trying to accomplish this should do the trick:

    $unique = array();
    foreach ($c as $arr) {
      if ( ! in_array($arr, $unique)) {
        $unique[] = $arr;
      }
    }
    
    var_dump($unique);
    

    This builds up a unique array by iterating over the original array and adding new elements as it encounters them.

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

Sidebar

Related Questions

After deploying WCF server (svc) on my Server, I have got this message when
After discovering about Javascript namespaces, I tried to implement them but I run into
After checking other SO posts, I did not find an answer to my question
After working on several large web applications, and seeing gigantic style sheets with no
After performing some Google-fu and searching Stack Overflow I've been unable to find a
After spending a few days of trying to find an answer online, I figured
After insert in excel formula bar i got unwanted character ' which restricts the
After bringing CardIO (iOS XCode) into my build, I am receiving a link error
After reading countless guides, tutorials and intros, I still can't get my app onto
After debugging a CodeIgniter application that were installed into a new development environment, 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.