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

  • Home
  • SEARCH
  • 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 357033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:10:03+00:00 2026-05-12T12:10:03+00:00

I have two arrays that I would like to compare and ultimately wind up

  • 0

I have two arrays that I would like to compare and ultimately wind up with a single array with everything combined, having no duplicates. Can someone please tell me which function I should use? There are so many that it’s a bit confusing.

$array1[]['name'] = 'Kim, Jones';
$array1[]['name'] = 'Jim, Miller';

array1 is an array I built that I want added to an array coming from the database. The key in the second array is also named “name”. Thanks.

EDIT:

I managed to merge these two arrays but I can still see duplicates.

This is what the first array looks like:

Array
(
    [0] => Array
        (
            [WNumber] => ADMIN
            [Name] => Tim, Cooley
            [Employer] => CalPERS
            [Student] => 1
            [Perm] => 1
            [QA] => 0
            [Supervisor] => 1
            [RQW] => 0
        )

My second array is built like this:

$add_names[]['Name']='Jim, Jones';

I just want to add $add_names to the first array WHERE there are no duplicates.

  • 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-12T12:10:04+00:00Added an answer on May 12, 2026 at 12:10 pm

    I’m tempted to sell you on CakePHP, since it has a number of functions that makes this easy in its “Set” class. Your problem is that you have the results in a nested array. A simple “array_unique” does not work in a nested array.

    I’d do it the old fashioned way…

    $array1[]['name'] = 'Kim, Jones';
    $array1[]['name'] = 'Jim, Miller';
    
    $array2[]['name'] = 'Kim, Jones';
    $array2[]['name'] = 'Jimbo, Miller';
    $array2[]['name'] = 'Jim, Jones';
    
    $new_array=array_merge($array1, $array2);
    $out_array = array();
    $key_array = array();
    foreach($new_array as $i => $row) {
            if (empty($key_array[$row['name']])) {
                    $out_array[] = $row;
            }
            $key_array[$row['name']] = 1;
    }
    
    print_r($out_array);
    

    This code works for me…

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

Sidebar

Ask A Question

Stats

  • Questions 235k
  • Answers 235k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I was able to figure it out using the example… May 13, 2026 at 6:13 am
  • Editorial Team
    Editorial Team added an answer select * from tableA inner join tableB on tableA.SIM1 =… May 13, 2026 at 6:13 am
  • Editorial Team
    Editorial Team added an answer There are numerous ways: have an "instance file" in /var/run… May 13, 2026 at 6:13 am

Related Questions

I have two arrays of strings that I would like to compare for equality:
i seem to be having difficulties in accessing and comparing objects in NSMutableArrays in
I am trying to compare two long bytearrays in VB.NET and have run into
I have two models, associated with a HABTM (actually using has_many :through on both

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.