I have two arrays like this.
$array1=array(1,2,3,4,5,7);
$array2=array(1,2,3,4,5,6);
So, the output should bring the difference in both arrays.
The output should be.
1,2,3,4,5 -> These numbers exist in both arrays, so these should be ignored.
7 and 6 -> These numbers are the un-common in both arrays, so I need these values in array.
The output should be 7 & 6.
Help me out. I have tried array_diff
and other array elements.
The array_diff() function compares the values of two (or more) arrays, and returns the differences. This function compares the values of two (or more) arrays, and return an array that contains the entries from array1 that are not present in array2 or array3, etc.
Using Arrays. equals(array1, array2) methods − This method iterates over each value of an array and compare using equals method. Using Arrays. deepEquals(array1, array2) methods − This method iterates over each value of an array and deep compare using any overridden equals method.
How to Compare Array Contents? A simple way is to run a loop and compare elements one by one. Java provides a direct method Arrays. equals() to compare two arrays.
JavaScript finding non-matching values in two arrays The code will look like this. const array1 = [1, 2, 3, 4, 5, 6]; const array2 = [1, 2, 3, 4, 5, 6, 7, 8, 9]; const output = array2. filter(function (obj) { return array1. indexOf(obj) === -1; }); console.
try this
array_merge(array_diff($array1,$array2),array_diff($array2,$array1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With