Skip to content
Advertisement

PHP compare arrays and remove NOT matched objects

I want to compare two arrays with each other and remove all objects from the first one who are NOT present in both arrays.

JavaScript

The result should be array1 without the ‘AAAAAAAAAAAAAAA’ object.

JavaScript

What I tried:

JavaScript

Advertisement

Answer

array_intersect_key is what you’re looking for. It takes two or more arrays, and returns a new array containing the elements of the first array, whose keys are present in all provided arrays.

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