Skip to content
Advertisement

How to merge two array and take only value in first array if there is no matching value in second array

I have two arrays :

JavaScript

I want to take the value only in $array1 if there is no same value in $array2, if there is a same value in $array2 filter it out.

Expected output if no same value available in $array2:

JavaScript

Expected output is there is same value in $array2:

JavaScript

Advertisement

Answer

Try array_diff() function

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