**已关闭。**此问题需要debugging details。当前不接受答案。
编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
昨天关门了。
Improve this question
我有一个维度数组,我想使用array_map添加一个名为“reschedule”的新键
这是我的阵:
$topics = [
[
"id" => 1,
"statusName" => "COMPLETED",
"lessons" => [
[
"id" => 1,
"statusName" => "COMPLETED"
],
[
"id" => 1,
"statusName" => "COMPLETED"
],
]
],
[
"id" => 2,
"statusName" => "SCHEDULED",
"lessons" => [
[
"id" => 1,
"statusName" => "SCHEDULED"
],
[
"id" => 1,
"statusName" => "COMPLETED"
],
]
]
];
我试过的代码:
foreach ($topics as $key => $value) {
$topics[$key]['lessons'] = array_map(function ($lesson) use ($value) {
$lesson['reschedule'] = true;
return $lesson;
}, $value['lessons']);
}
我想添加' reschedule
'键到每一课,但它不工作,为我的财产。
所需输出:
[
"id" => 1,
"statusName" => "COMPLETED",
"lessons" => [
[
"id" => 1,
"statusName" => "COMPLETED",
"reschedule" => true
],
[
"id" => 1,
"statusName" => "COMPLETED",
"reschedule" => true
],
]
]
1条答案
按热度按时间zd287kbt1#