3v4l.org

run code in 300+ PHP versions simultaneously
<?php function condense_duplicates($arrays) { $machine_slot_map = array(); foreach ($arrays as $arr) { $machine_slot_key = "{$arr['MACHINE']}_{$arr['slot']}"; if (array_key_exists($machine_slot_key, $machine_slot_map)) { $lot = $arr['LOT']; if (array_key_exists('Duplicate', $machine_slot_map[$machine_slot_key])) { $curr_duplicates = $machine_slot_map[$machine_slot_key]['Duplicate']; $machine_slot_map[$machine_slot_key]['Duplicate'] = "{$curr_duplicates}, {$lot}"; } else { $machine_slot_map[$machine_slot_key]['Duplicate'] = $lot; } } else { $machine_slot_map[$machine_slot_key] = $arr; } } return array_values($machine_slot_map); } $arrays = array ( array('MACHINE' => 'A1', 'LOT' => 'B1077', 'slot' => 1), array('MACHINE' => 'A2', 'LOT' => 'B0229', 'slot' => 2), array('MACHINE' => 'A2', 'LOT' => 'B0132', 'slot' => 2), array('MACHINE' => 'A2', 'LOT' => 'B3967', 'slot' => 2), array('MACHINE' => 'A3', 'LOT' => 'B2644', 'slot' => 3) ); // echo 'Before:', PHP_EOL; // print_r($arrays); $arrays_with_condensed_duplicates = condense_duplicates($arrays); // echo 'After:', PHP_EOL; print_r($arrays_with_condensed_duplicates); ?>
Output for 7.2.0 - 7.2.34, 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.27, 8.4.1 - 8.4.14, 8.5.0
Array ( [0] => Array ( [MACHINE] => A1 [LOT] => B1077 [slot] => 1 ) [1] => Array ( [MACHINE] => A2 [LOT] => B0229 [slot] => 2 [Duplicate] => B0132, B3967 ) [2] => Array ( [MACHINE] => A3 [LOT] => B2644 [slot] => 3 ) )
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:
219.05 ms | 408 KiB | 5 Q