Skip to content
Advertisement

How to compare two arrays using a for loop and keep the unique from first array?

how to compare two array value and remove the duplicate value from the first array using php for example

JavaScript

I tried this:

JavaScript

Advertisement

Answer

This is probably a duplicate, but I’m bored. Just compute the difference:

JavaScript

Or loop the main array, check for each value in the other and if found unset from the main array:

JavaScript

Or loop the other array, search for each value in the main array and use the key found to unset it:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement