3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array_one = [ [ 'product_id' => 1, 'product_stock' => '1.2', 'stock_date' => '2022-02-15' ], [ 'product_id' => 2, 'product_stock' => '5', 'stock_date' => '2022-02-15' ], ]; $array_two = [ [ 'product_id' => 1, 'product_slug' => 'product_one', 'product_description' => 'this is the product one' ], [ 'product_id' => 2, 'product_slug' => 'product_two', 'product_description' => 'this is the product two' ], [ 'product_id' => 3, 'product_slug' => 'product_three', 'product_description' => 'this is the product three' ], ]; $lookup = array_column($array_two, null, 'product_id'); var_export( array_map( fn($row) => $row + $lookup[$row['product_id']], $array_one ) );

preferences:
70.7 ms | 406 KiB | 5 Q