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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:21:05+00:00 2026-06-14T22:21:05+00:00

I have the following tested code that after a couple of tries does the

  • 0

I have the following tested code that after a couple of tries does the job to filter unique results out of two merged arrays. I previously tried using array_diff, array_diff_key, array_diff_assoc to no avail until I settled with the following.

  • The second needs to first exclude empty values (like 0) using array_filter, otherwise empty values (“red” => “0”) are also printed in the merged result which is not expected.
  • array_unique removes duplicates from the merge.

So the following is working as expected, but I wonder if there is any betterment to the code which looks a bit like winding around. I meant I am not confident if the code is properly done:

$array1 = array("a" => "green", "b" => "purple", "blue" => "0");
$array2 = array("a" => "0", "b" => "purple", "blue" => "blue", "red" => "0");

$merge  = array_unique(array_merge($array1, array_values(array_filter($array2))));

Any betterment is much appreciated. Thanks

UPDATE:
Sorry, I was evolving late in the requirement, that later I realized I should also consider replacing the first array1 with array2 even when NULL return when pairs exists in both. I had better go back to my drawing room. Thanks

  • 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-14T22:21:07+00:00Added an answer on June 14, 2026 at 10:21 pm

    I din get what exactly you want, but as per your codes result, i guess this or something like this will work for you.

    $merge = $array1 + array_filter($array2);

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

Sidebar

Related Questions

Why doesn't following code work correctly in FireFox 3.6? I have tested in IE7,
I have the following code that uses the SqlClient.ExecuteScalar method to return an ID
I have something that looks like the following: [CoolnessFactor] interface IThing {} class Tester
I have following fiddle: http://jsfiddle.net/BFSH4/ As you see there are two issues: The h1
I have following script that executes all the .reg files in the current directory.
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig
I have the following code: private void SetControlNumbers() { string controlString = ; int
Why does the following simplified code not sets the font-size of the TextBlock to
I have used the following code before uploading an image into mysql database Before
I have the following code which when looking at it while it's running shows

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.