【发布时间】:2018-12-27 03:13:39
【问题描述】:
数组 1
array(1) {
[0]=>
array(3) {
["shoplist_id"]=>
int(11)
["shoplist_name"]=>
string(18) "PM_Mon_Wed_Fri_Sun"
["shoplist_status"]=>
int(0)
}
}
数组 2
array(3) {
[2184]=>
array(3) {
["shoplist_id"]=>
int(11)
["shoplistshop_id"]=>
int(7)
["shoplistshop_status"]=>
int(0)
}
[2184]=>
array(3) {
["shoplist_id"]=>
int(11)
["shoplistshop_id"]=>
int(8)
["shoplistshop_status"]=>
int(0)
}
}
[2185]=>
array(3) {
["shoplist_id"]=>
int(11)
["shoplistshop_id"]=>
int(9)
["shoplistshop_status"]=>
int(0)
}
}
我想要什么
array(2) {
[0]=>
array(3) {
["shoplist_id"]=>
int(11)
["shoplist_name"]=>
string(18) "PM_Mon_Wed_Fri_Sun"
["shoplist_status"]=>
int(0)
array(3) {
[0]=>
array(2) {
["shoplistshop_id"]=>
int(7)
["shoplistshop_status"]=>
int(0)
}
[1]=>
array(2) {
["shoplistshop_id"]=>
int(8)
["shoplistshop_status"]=>
int(0)
}
[2]=>
array(2) {
["shoplistshop_id"]=>
int(9)
["shoplistshop_status"]=>
int(0)
}
}
}
}
主键是 shoplist_id。
我需要合并数组 1 和数组 2,因为它们具有相同的键和值。
我尝试使用 array_merge / array_merge_recursive 似乎不起作用。
那么如何合并具有相同键和相同值的数组 1 和 2? 那是我想念的吗?非常感谢。
【问题讨论】:
-
看看this question你的答案会很相似
-
您从哪里获得阵列 1 和阵列 2?您想要的结果是无效的语法。您的子数组需要有一个键。