gpt4 book ai didi

php - 合并具有相同数量项目的 2 个数组 - php

转载 作者:行者123 更新时间:2023-12-05 03:31:47 25 4
gpt4 key购买 nike

<分区>

两个数组 $newResponse$key 中的项数将始终相同。对于 $newResponse 的每个项,我想要将 $key 的项目添加到 $newResponse 中,按照它们在 $key 数组中存在的相同顺序,如 Expected result 中所述。我怎样才能做到这一点?

dump($newResponse); 是一个如下所示的数组,它是 foreach 循环的结果。

array:4 [
0 => array:6 [
"courseId" => 18
"courseDisplayName" => "qqq"
]
1 => array:6 [
"courseId" => 1
"courseDisplayName" => "ips"
]
2 => array:6 [
"courseId" => 18
"courseDisplayName" => "qqq"
]
3 => array:6 [
"courseId" => 1
"courseDisplayName" => "ips"
]
]

dump($key); 是一个如下所示的数组,它是另一个 foreach 循环的结果。

array:4[
0=>[
"totalPoints" => 2
"percent" => 1.0
"id" => 2
]
1=> [
"totalPoints" => 10
"percent" => 2
"id" => 3
]
2=> [
"totalPoints" => 4
"percent" => 0.0
"id" => 6
]
3=> [
"totalPoints" => 4
"percent" => 0.0
"id" => 5
]
]

预期结果:

[
[
"courseId" => 18
"courseDisplayName" => "qqq"
"totalPoints" => 2
"percent" => 1.0
"id" => 2
]
[
"courseId" => 1
"courseDisplayName" => "ips"
"totalPoints" => 10
"percent" => 2
"id" => 3
]
[
"courseId" => 18
"courseDisplayName" => "qqq"
"totalPoints" => 4
"percent" => 0.0
"id" => 6
]
[
"courseId" => 1
"courseDisplayName" => "ips"
"totalPoints" => 4
"percent" => 0.0
"id" => 5
]
]

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com