3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arrays = [ ['id' => 1, 'name' => '', 'cat_name' => 'Food & Beverage', 'quantity' => 1, 'price' => 25, 'image' => 'books_image/calories_fat_carbohydrate.png'], ['id' => 2, 'name' => '', 'cat_name' => 'Food & Beverage', 'quantity' => 5, 'price' => 38, 'image' => 'books_image/the_law_relating_to_food.png'], ['id' => 3, 'name' => '', 'cat_name' => 'Food & Beverage', 'quantity' => 5, 'price' => 19, 'image' => 'books_image/it_starts_with_food.png'], ['id' => 1, 'name' => '', 'cat_name' => 'Food & Beverage', 'quantity' => 2, 'price' => 19, 'image' => 'books_image/it_starts_with_food.png'] ]; $result = array_values(array_reduce($arrays, function($result, $entry) { if (isset($result[$entry['id']])) { $result[$entry['id']]['quantity'] += $entry['quantity']; } else { $result[$entry['id']] = $entry; } return $result; }, [])); var_dump($result);
Output for git.master, git.master_jit, rfc.property-hooks
array(3) { [0]=> array(6) { ["id"]=> int(1) ["name"]=> string(0) "" ["cat_name"]=> string(15) "Food & Beverage" ["quantity"]=> int(3) ["price"]=> int(25) ["image"]=> string(41) "books_image/calories_fat_carbohydrate.png" } [1]=> array(6) { ["id"]=> int(2) ["name"]=> string(0) "" ["cat_name"]=> string(15) "Food & Beverage" ["quantity"]=> int(5) ["price"]=> int(38) ["image"]=> string(40) "books_image/the_law_relating_to_food.png" } [2]=> array(6) { ["id"]=> int(3) ["name"]=> string(0) "" ["cat_name"]=> string(15) "Food & Beverage" ["quantity"]=> int(5) ["price"]=> int(19) ["image"]=> string(35) "books_image/it_starts_with_food.png" } }

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:
29.4 ms | 407 KiB | 5 Q