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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
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 ) ) )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
176.71 ms | 408 KiB | 5 Q