3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['id[0]' => 'BX-78', 'Name[0]' => 'XXX', 'Address[0]' => 'YUUSATD'], ['id[1]' => 'BX-79', 'Name[1]' => 'YYY', 'Address[1]' => 'DHJSHDJGY'], ['id[2]' => 'BX-80', 'Name[2]' => 'ZZZ', 'Address[2]' => 'DDSDSDA'], ['id[3]' => 'BX-78', 'Name[3]' => 'AAA', 'Address[3]' => 'FSDSDS'], ['id[4]' => 'BX-81', 'Name[4]' => 'XXX', 'Address[4]' => 'DSDSDSD'] ]; $dupes = []; $current = []; foreach ($array as $index => $entry) { $idKey = "id[$index]"; $nameKey = "Name[$index]"; if (array_key_exists($entry[$idKey], $current)) { $dupes[] = [$entry, $current[$entry[$idKey]]]; } elseif (array_key_exists($entry[$nameKey], $current)) { $dupes[] = [$entry, $current[$entry[$nameKey]]]; } else { $current[$entry[$idKey]] = $current[$entry[$nameKey]] = $entry; } } print_r($dupes);
Output for 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Array ( [0] => Array ( [0] => Array ( [id[3]] => BX-78 [Name[3]] => AAA [Address[3]] => FSDSDS ) [1] => Array ( [id[0]] => BX-78 [Name[0]] => XXX [Address[0]] => YUUSATD ) ) [1] => Array ( [0] => Array ( [id[4]] => BX-81 [Name[4]] => XXX [Address[4]] => DSDSDSD ) [1] => Array ( [id[0]] => BX-78 [Name[0]] => XXX [Address[0]] => YUUSATD ) ) )

preferences:
168.59 ms | 404 KiB | 152 Q