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" ], (object)["item_id" => "91", "name" => "Poires Guyot (bio)", "product_id" => "690", "meta_key" => "_backorders", "meta_value" => "no" ], (object)["item_id" => "91", "name" => "Poires Guyot (bio)", "product_id" => "690", "meta_key" => "_sold_individually", "meta_value" => "no" ] ]; $result = []; foreach($products as $product) { $result[$product->item_id][$product->meta_key] = $product->meta_value; } var_export($result);
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
array ( 89 => array ( 'vmm_warehouse_sg_10783' => '0', 'vmm_warehouse_sg_10782' => '0', ), 91 => array ( '_backorders' => 'no', '_sold_individually' => 'no', ), )

preferences:
139.62 ms | 408 KiB | 5 Q