<?php
$oldArr = [
[
"color" => "red",
"shape" => "circle",
"size" => "small",
],
[
"color" => "green",
"shape" => "square",
"size" => "large",
],
[
"color" => "yellow",
"shape" => "triangle",
"size" => "large",
],
];
$newVals = ["large", "large", "small"];
var_export(
array_replace_recursive(
$oldArr,
array_map(fn($size) => ['size' => $size], $newVals)
)
);
- Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- array (
0 =>
array (
'color' => 'red',
'shape' => 'circle',
'size' => 'large',
),
1 =>
array (
'color' => 'green',
'shape' => 'square',
'size' => 'large',
),
2 =>
array (
'color' => 'yellow',
'shape' => 'triangle',
'size' => 'small',
),
)
preferences:
107.62 ms | 403 KiB | 91 Q