3v4l.org

run code in 300+ PHP versions simultaneously
<?php $line_items = [ ['price' => 41.99, 'id' => 12, 'quantity' => 1], ['price' => 155.95, 'id' => 11, 'quantity' => 1], ['price' => 21, 'id' => 13, 'quantity' => 1] ]; $price_array = [ 197.94, 21.00 ]; $result = []; foreach ($line_items as $row) { $lastKey = array_key_last($result); if ( !$result || array_sum(array_column($result[$lastKey], 'price')) == $price_array[$lastKey] ) { unset($ref); $result[] = &$ref; } $ref[] = $row; } var_export($result);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 0 => array ( 'price' => 41.99, 'id' => 12, 'quantity' => 1, ), 1 => array ( 'price' => 155.95, 'id' => 11, 'quantity' => 1, ), ), 1 => array ( 0 => array ( 'price' => 21, 'id' => 13, 'quantity' => 1, ), ), )

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:
61.49 ms | 406 KiB | 5 Q