Best way to get for each element of an array all similar elements from another array in PHP?

  arrays, object, optimization, php, search

So I have two arrays of objects in PHP (each object contains name and email). What am I looking for is the fastest way to get for each element of the first array, all the elements from the second array that have a similar name or email (I am using the similar_text function to achieve this).

The way I am doing it now is with two foreach functions comparing every element of the first array to every element of the second array (and doing some customization of the results, but that is not really important). Is there any better way to achieve this? Because for a large number of elements it can take a very long time.

I am using PHP 7.3.12, so a solution that can be done with this version is appreciated.

Thank you!

Source: Ask PHP

LEAVE A COMMENT