3v4l.org

run code in 300+ PHP versions simultaneously
<?php $products = [ 1031 => [ 'id' => '1031', 'name' => 'TR16', 'price' => 98.75 ], 1032 => [ 'id' => '1032', 'name' => 'TR16G', 'price' => 148.75 ] ]; $newItemIds = [ 1031 => [ 'id' => 1031, 'quantity' => 4 ], 1032 => [ 'id' => 1032, 'quantity' => 2 ] ]; $products_with_quantity = array_replace_recursive($products, $newItemIds); print_r($products_with_quantity);

preferences:
180.66 ms | 405 KiB | 5 Q