3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ["Reservation" => ["adult_price" => 200, "adult_count" => 2]], ["Reservation" => ["adult_price" => 200, "adult_count" => 1]], ["Reservation" => ["adult_price" => 300, "adult_count" => 1]], ["Reservation" => ["adult_price" => 200, "adult_count" => 1]], ]; $grouped = []; foreach ($array as $item) { $item = $item["Reservation"]; $currentValue = isset($grouped[$item["adult_price"]]) ? $grouped[$item["adult_price"]] : 0; $grouped[$item["adult_price"]] = $currentValue + $item["adult_count"]; } $buildArray = []; foreach ($grouped as $price => $count) { $buildArray[] = ["Reservation" => ["adult_price" => $price, "adult_count" => $count]]; } print_r($buildArray);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => Array ( [Reservation] => Array ( [adult_price] => 200 [adult_count] => 4 ) ) [1] => Array ( [Reservation] => Array ( [adult_price] => 300 [adult_count] => 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:
70.47 ms | 402 KiB | 8 Q