Array
(
[0] => Array
(
[product_id] => 200
[options] => Array
(
[0] => Array
(
[quantity] => 1
[option_id] => 199
[option_value_id] => 500
)
)
)
[1] => Array
(
[product_id] => 201
[options] => Array
(
[0] => Array
(
[quantity] => 1
[option_id] => 200
[option_value_id] => 501
)
)
)
)
[0] => Array
(
[product_id] => 201
[options] => Array
(
[0] => Array
(
[quantity] => 5
[option_id] => 200
[option_value_id] => 501
)
)
)
Array
(
[0] => Array
(
[product_id] => 200
[options] => Array
(
[0] => Array
(
[quantity] => 1
[option_id] => 199
[option_value_id] => 500
)
)
)
[1] => Array
(
[product_id] => 201
[options] => Array
(
[0] => Array
(
[quantity] => 6
[option_id] => 200
[option_value_id] => 501
)
)
)
)
$products = [
[
'product_id' => 200,
'options' => [
[
'quantity' => 1,
'option_id' => 199,
'option_value_id' => 500,
]
],
],
[
'product_id' => 201,
'options' => [
[
'quantity' => 1,
'option_id' => 200,
'option_value_id' => 501,
]
],
],
];
$newProduct = [
'product_id' => 201,
'options' => [
[
'quantity' => 5,
'option_id' => 200,
'option_value_id' => 501,
]
],
];
$products = array_map(function (array $product) use ($newProduct) {
if ($product['product_id'] === $newProduct['product_id']) {
$product['options'][0]['quantity'] += $newProduct['options'][0]['quantity'];
}
return $product;
}, $products);
var_dump($products);