<?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
)
);
- Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.13
- array (
0 =>
array (
'product_id' => 1,
'product_stock' => '1.2',
'stock_date' => '2022-02-15',
'product_slug' => 'product_one',
'product_description' => 'this is the product one',
),
1 =>
array (
'product_id' => 2,
'product_stock' => '5',
'stock_date' => '2022-02-15',
'product_slug' => 'product_two',
'product_description' => 'this is the product two',
),
)
preferences:
104.14 ms | 407 KiB | 5 Q