我有2个阵列在PHP语言:PHP合并2个阵列基于相同的特定键
Array
(
[0] => Array
(
[amount] => 21600.00
[rows] => 2
[student_id] => 1
)
)
和
Array
(
[0] => Array
(
[amount] => 541990.00
[rows] => 512
[student_id] => 1
)
[1] => Array
(
[amount] => 347480.00
[rows] => 281
[student_id] => 2
)
[2] => Array
(
[amount] => 507400.00
[rows] => 214
[student_id] => 3
)
)
我想基于相同student_id数据值合并这两个数组,所以我希望得到的结果会是这样:
Array
(
[0] => Array
(
[amount] => 563590.00
[rows] => 514
[student_id] => 1
)
[1] => Array
(
[amount] => 347480.00
[rows] => 281
[student_id] => 2
)
[2] => Array
(
[amount] => 507400.00
[rows] => 214
[student_id] => 3
)
)
我试图array_merge和array_merge_recursive但他们没有给我牛逼他预计结果,谢谢!
我只是使用一个foreach()循环 – rtfm
为什么你有这2个数组具有相同的相似性结构?你是从两张不同的表中选择它吗?我认为你应该在数据库级别做到这一点。 –
是的,我知道,但我不能通过查询。所以我应该通过PHP来完成。顺便说一句我现在从Rahul得到了答案 –