3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ (object)['id' => 1, 'nome' => 'T.SHIRT', 'quantita' => 2,], (object)['id' => 2, 'nome' => 'Sweatshirt', 'quantita' => 4,], (object)['id' => 1, 'nome' => 'T.SHIRT', 'quantita' => 4,], ]; $store = []; foreach($arr as $record) { if(isset($store[$record->id])) { $store[$record->id]->quantita += $record->quantita; } else $store[$record->id] = $record; } var_dump($store);
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { [1]=> object(stdClass)#1 (3) { ["id"]=> int(1) ["nome"]=> string(7) "T.SHIRT" ["quantita"]=> int(6) } [2]=> object(stdClass)#2 (3) { ["id"]=> int(2) ["nome"]=> string(10) "Sweatshirt" ["quantita"]=> int(4) } }

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