3v4l.org

run code in 500+ PHP versions simultaneously
<?php $stocks = collect( [ ['sku' => '123', 'batch' => '123', 'manufacturing_date' => 2021, 'qty_total' => 1], ['sku' => '123', 'batch' => '123', 'manufacturing_date' => 2021, 'qty_total' => 2], ['sku' => '123', 'batch' => '123', 'manufacturing_date' => 2020, 'qty_total' => 3], ['sku' => '5', 'batch' => '123', 'manufacturing_date' => 2020, 'qty_total' => 4], ] ); return $stocks->groupBy(['sku','batch' , 'manufacturing_date'], true)->map(function($items){ $firstItem = $items->values()->first()->values()->first(); return collect($firstItem->first())->merge([ 'qty_total' => $firstItem->sum('qty_total') ]); })->values();
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Call to undefined function collect() in /in/bVqEN6:3 Stack trace: #0 {main} thrown in /in/bVqEN6 on line 3
Process exited with code 255.

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:
54.67 ms | 989 KiB | 4 Q