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 I was convinced that labeled breaks/continues are a total nono over here ,
After looking at several options to rotate the text vertically I concluded that jangle
After following: https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview I can sign up a user via Facebook. But I'm struggling
After inserting new data into a table, I need to select some of the
After reading lots of sample code into this matter, I'm trying to figure out
After downloading/installing Android SDK, it put the files/folders here: C:\Program Files (x86)\Android\android-sdk if I
After debugging a CodeIgniter application that were installed into a new development environment, I
After developing mini project with WCF duplex (Chat Service | Sms Service), I got
After I click button1, it display 0, why? How can get correct width of
After programming a little in C I decided to jump right into C++. At

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.