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
Barmar’s comment is correct,
array_diffandarray_intersectare what you want. You have a typo in your question though, “100” appears in both the matches and the new values arrays.My guess… you’re processing checkboxes or multi-selects to determine what to keep, what to add and what to remove.