3v4l.org

run code in 300+ PHP versions simultaneously
<?php $products = [ (object)["item_id" => "89", "name" => "Confiture de Myrtilles", "product_id" => "737", "meta_key" => "vmm_warehouse_sg_10783", "meta_value" => "0" ], (object)["item_id" => "89", "name" => "Confiture de Myrtilles", "product_id" => "737", "meta_key" => "vmm_warehouse_sg_10782", "meta_value" => "0" ] ]; $result = (object)[]; foreach($products as $product) { if (!isset($result->{$product->item_id})) { $result->{$product->item_id} = (object)[]; } $result->{$product->item_id}->{$product->meta_key} = $product->meta_value; } var_export($result);

preferences:
27.3 ms | 404 KiB | 5 Q