1 回答
TA贡献1777条经验 获得超3个赞
使用已知的第一级键和您发明的第二级键将 array2 数据推送到 array1 中。
代码:(演示)
$array1 = array ( 'item1' => array ( 'myValues' => array ( 1 => 5, 2 => 1, ), ), 'item2' => array ( 'myValues' => array ( 1 => 5, 2 => 1, ), ), );
$array2 = array ( 'item1' => array ( 1 => 2, ), 'item2' => array ( 1 => 5, 2 => 1, ), );
foreach ($array2 as $key => $subarray) {
$array1[$key]['myValues2'] = $subarray;
}
var_export($array1);
输出:
array (
'item1' =>
array (
'myValues' =>
array (
1 => 5,
2 => 1,
),
'myValues2' =>
array (
1 => 2,
),
),
'item2' =>
array (
'myValues' =>
array (
1 => 5,
2 => 1,
),
'myValues2' =>
array (
1 => 5,
2 => 1,
),
),
)
- 1 回答
- 0 关注
- 67 浏览
添加回答
举报