我需要将更多的键和值推送到数组中。如果我使用下面的代码,第一个键值对会被第二个替换。
供您参考:
代码如下:
供您参考:
代码如下:
foreach ($projectData['projectsections'] as $key => $name) {
$projectData['projectsections'][$key] = ['name' => $name];
$projectData['projectsections'][$key]= ['id' => '1'];
}
当前结果:
'projectsections' => [
(int) 0 => [
'id' => '1'
],
(int) 1 => [
'id' => '1'
]
],
期望结果:
'projectsections' => [
(int) 0 => [
'name' => 'test1',
'id' => '1'
],
(int) 1 => [
'name' => 'test2',
'id' => '1'
]
],
我该如何在PHP中构建这个数组?有人可以帮忙吗?