【发布时间】:2021-12-02 08:42:56
【问题描述】:
你好,我有一个两个 json 对象的
Json 1
{
"id": null,
"type": "NE",
"info": {
"name": "Ne",
"last_name: "NE",
"status": "NE",
"rfc": "NE",
"email": "jNE"
}
}
json 2
{
"id": 2,
"type": "PF",
"info": {
"status": 1,
"rfc": "DOSLWOOEOE22",
"email": "email@email.com"
}
}
我需要合并 json 对象的,当 json 2 覆盖 json 1 中的值,但 json 结果包含 json 没有的键/值
我需要同样的 json 结果:
{
"id": 2,
"type": "PF",
"info": {
"name": "Ne",
"last_name: "NE",
"status": 1,
"rfc": "DOSLWOOEOE22",
"email": "email@email.com"
}
}
**注意:我尝试使用 array_merge 但不起作用,仅将 json 2 覆盖为 json 1 而无需其他键 **
【问题讨论】:
-
array_merge_recursive效果更好吗? -
与 array_replace_recursive 一起使用,谢谢
标签: php json laravel array-merge