Greetings. There is such a task
Suppose there are 2 multi-dimensional arrays
One of them (let it be $ array1 ):
Array ( [299292] => Array ( [ID] => 299292 [ID_EL] => [ARTICUL] => 336867 [TOVAR] => Шезлонг Garden Way LOUIS-A 76015 черный [MODEL] => LOUIS-A 76015 черный [ROD] => Спорт и отдых [CATEGORY] => Спорт и отдых [SUBCATEGORY] => Качели и гамаки [PRICE] => 7200 [BRAND] => Garden Way [NAME] => Шезлонг [RRC] => РРЦ ) [299291] => Array ( [ID] => 299291 [ID_EL] => [ARTICUL] => 336866 [TOVAR] => Шезлонг Garden Way LOUIS-A 76015 бежевый [MODEL] => LOUIS-A 76015 бежевый [ROD] => Спорт и отдых [CATEGORY] => Спорт и отдых [SUBCATEGORY] => Качели и гамаки [PRICE] => 7200 [BRAND] => Garden Way [NAME] => Шезлонг [RRC] => РРЦ ) [299290] => Array ( [ID] => 299290 [ID_EL] => [ARTICUL] => 336865 [TOVAR] => Шезлонг Garden Way BRIGO 770505 черный [MODEL] => BRIGO 770505 черный [ROD] => Спорт и отдых [CATEGORY] => Спорт и отдых [SUBCATEGORY] => Качели и гамаки [PRICE] => 5700 [BRAND] => Garden Way [NAME] => Шезлонг [RRC] => РРЦ ) /*и тд*/ ) The second array is $ array2 :
Array ( [111113] => Array ( [ID] => 1314124 [NAME] => Шезлонг Garden Way LOUIS-A123 76015 черный ) [111112] => Array ( [ID] => 299291 [NAME] => Шезлонг Garden Way LOUIS-A12 76015 бежевый ) [11111] => Array ( [ID] => 13253325 [NAME] => Шезлонг Garden Way BRIGO 770505 черный ) /*и тд*/ ) Each array contains 10,000+ nested arrays.
I need to compare the first array using the TOVAR key with the second array using the NAME key. If there is a match, perform some simple operations. But that's not the point. The question is: how to do it as quickly and efficiently as possible?
After all, sorting (comparison algorithm) type:
foreach($array1 as $row) foreach ($array2 as $cat) if ($row['TOVAR']==$cat['NAME']) echo 'Равны: '.$row['TOVAR'].' и '.$cat['NAME'].'<br/>'; else echo 'Не равны: '.$row['TOVAR'].' и '.$cat['NAME'].'<br/>'; will run idle on many iterations and it will greatly affect the speed. How to use array_intersect () in my case; I also do not know, because the comparison is based on different keys (and a separate array is not needed). I think the operations should be carried out immediately in a loop on the fly (in case of coincidence, for example, you need to copy the ID from the second array instead of the ID array of the first)
What do you advise? Thank!