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 git.master, git.master_jit, rfc.property-hooks
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 ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
110.23 ms | 406 KiB | 5 Q