3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['id' => 1, 'product_id' => 4, 'product_number' => 10, 'moving_type' => 1], ['id' => 1, 'product_id' => 5, 'product_number' => 10, 'moving_type' => 1], ['id' => 1, 'product_id' => 5, 'product_number' => 2, 'moving_type' => 2] ]; foreach ($array as $row) { if (!isset($result[$row['product_id']])) { $result[$row['product_id']] = array_slice($row, 0, 3, true); } else { $result[$row['product_id']]['product_number'] += ($row['moving_type'] == 1 ? 1 : -1) * $row['product_number']; } } var_export(array_values($result));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'id' => 1, 'product_id' => 4, 'product_number' => 10, ), 1 => array ( 'id' => 1, 'product_id' => 5, 'product_number' => 8, ), )

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:
163.44 ms | 405 KiB | 5 Q