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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:34:55+00:00 2026-06-13T05:34:55+00:00

I have 2 arrays. One would be the original data, the other would be

  • 0

I have 2 arrays. One would be the original data, the other would be the new data. Between the 2 of them there could be matching values. And I need to figure out from the new inbound array what’s new, what’s a match, and what’s not a match.

The end goal is that I need these 3 arrays, one of items removed from the original, one of items that are new entries, and then the original entries that matched anything in the new entries.

I was thinking something to the extent of starting off with 3 blank arrays to fill as I cycle over the original or new with a loop and compare them adding each type old, new, removing to there respective array so I can work with the results there after. Which I can piece together an idea in my head that works for 2 arrays as the output, but the 3rd I get lost on. So Im kinda hindged on this bit for the moment. looking for advice and or help Creating a loop or something better that will yield the 3 sets of results I am looking for.

Array of original data from database:

Array(
      15,
      22,
      100,
      1500,
      2000,
      500,
      3000,
      1101
   )

Array of inbound new data

Array(
      100,
      800,
      920,
      1500,
      2000,
      1603,
      500,
      3000,
      1101
   )

Array of expected matches between original and inbound new:

Array(
      100,
      1500,
      2000,
      500,
      3000,
      1101
   )

Array of expected “new” entries between original and new:

Array(
      100,
      800,
      920,
      1603
   )

Array of expected entries from old that don’t match between original and new:

Array(
      15,
      22
   )

It may not be spot on as I obviously just hand typed these.. but hopefully it demonstrates what Im trying to achieve to some extent

  • 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-13T05:34:57+00:00Added an answer on June 13, 2026 at 5:34 am

    Barmar’s comment is correct, array_diff and array_intersect are what you want. You have a typo in your question though, “100” appears in both the matches and the new values arrays.

    <?php
    $orig = array(15, 22, 100, 1500, 2000, 500, 3000, 1101);
    $post = array(100, 800, 920, 1500, 2000, 1603, 500, 3000, 1101);
    
    // Gets things in both arrays
    $matches = array_intersect($orig, $post);
    // Gets things in $post that aren't in $orig
    $new     = array_diff($post, $orig);
    // Gets things in $orig that aren't in $post
    $removed = array_diff($orig, $post);
    
    foreach (array($orig, $post, $matches, $new, $removed) as $array) {
        print_r($array);
    }
    

    My guess… you’re processing checkboxes or multi-selects to determine what to keep, what to add and what to remove.

    • 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 render in a template, one
Say I have two arrays where one is a permutation of the other: A
I have 3 arrays, one has low value weight, the other high value weights,
I have two arrays, one is very large (more than million entries) and other
Say I have an array: $before = array(1,2,3,3,4,4,4,5) How would I remove just one
So far, I have 2 arrays: one with stock codes and one with a
I have two arrays and I post the arrays in one input; <input name='sistem[]'
I have two arrays the first one has this structure Parameter Keys array array
I have some Javascript code that creates 2 arrays: One for Product Category and
I have two arrays, the first one contents numbers and the second one use

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.