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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:35:44+00:00 2026-05-16T07:35:44+00:00

I have 2 arrays that I’m trying to get the unique values only from

  • 0

I have 2 arrays that I’m trying to get the unique values only from them. So I’m not just trying to remove duplicates, I’m actually trying to remove both duplicates.

So if I’m getting the 2 arrays like this:

$array1 = array();
$array2 = array();

foreach($values1 as $value1){ //output: $array1 = 10, 15, 20, 25;
    $array1[] = $value1;
}   

foreach($values2 as $value2){ //output: $array2 = 10, 15, 100, 150;
    $array2[] = $value2;
}

The final output I’m looking for is

$output = 20, 25, 100, 150;

Any neat way to getting this done?

  • 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-16T07:35:45+00:00Added an answer on May 16, 2026 at 7:35 am

    The other answers are on the right track, but array_diff only works in one direction — ie. it returns the values that exist in the first array given that aren’t in any others.

    What you want to do is get the difference in both directions and then merge the differences together:

    $array1 = array(10, 15, 20, 25);
    $array2 = array(10, 15, 100, 150);
    $output = array_merge(array_diff($array1, $array2), array_diff($array2, $array1));
    // $output will be (20, 25, 100, 150);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 arrays that i would like to loop through and combine into
I have multiple global arrays that a single method performs operations on. The method
I have 2 arrays in PHP that look something like this: $rows = array(11,12,14,14,11,13,12,11);
I have an Array of Arrays that contains numbers in a particular order. I
Lets say I have the following two PHP arrays that contain integers: $foo =
I'm having a problem lately that's driving me crazy. I have a multi-dimensional array
I am working on a project where I have to perform calculations on arrays
I have a function which determines if an array needs to be smoothed. I
I have a static class I'm using as my data layer in my website.
I'm wondering how I might go about searching the array below for the key

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.