3v4l.org

run code in 300+ PHP versions simultaneously
<?php $majorEarning = array( array( 'user_id' => 1, 'booking_id' => 2, 'price' => 30 ), array( 'user_id' => 2, 'booking_id' => 1, 'price' => 60 ), array( 'user_id' => 2, 'booking_id' => 6, 'price' => 10 ), array( 'user_id' => 1, 'booking_id' => 4, 'price' => 50 ) ); $r = []; foreach($majorEarning as $v){ array_key_exists($v['user_id'], $r) ? ($r[$v['user_id']]['booking_data'][] = ['booking'=>$v['booking_id'],'price'=>$v['price']]) : ($r[$v['user_id']] = ['user_id' => $v['user_id'], 'booking_data' => [['booking'=>$v['booking_id'], 'price'=>$v['price']]]]); } print_r($r);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [1] => Array ( [user_id] => 1 [booking_data] => Array ( [0] => Array ( [booking] => 2 [price] => 30 ) [1] => Array ( [booking] => 4 [price] => 50 ) ) ) [2] => Array ( [user_id] => 2 [booking_data] => Array ( [0] => Array ( [booking] => 1 [price] => 60 ) [1] => Array ( [booking] => 6 [price] => 10 ) ) ) )

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:
106.15 ms | 408 KiB | 5 Q