【发布时间】:2019-01-15 08:49:35
【问题描述】:
我已按照 PHP 中this answer 中提供的步骤进行操作。
但是,我想通过以下方式添加array_answer中的项目:
[
{
"id": "4c42ff61-148c-11e9-b673-005056be36b2",
"answer": "1",
"id_question": "11",
"pi": null,
"ca": null,
"pic": null,
"new_deadline": null,
"reason": null,
"notes": null,
"deadline": null
},
{
"id": "59a09a34-148c-11e9-b673-005056be36b2",
"answer": "3",
"id_question": "12",
"pi": null,
"ca": null,
"pic": null,
"new_deadline": null,
"reason": null,
"notes": null,
"deadline": null
},
{
"id": "66774e30-148c-11e9-b673-005056be36b2",
"answer": "3",
"id_question": "14",
"pi": null,
"ca": null,
"pic": null,
"new_deadline": null,
"reason": null,
"notes": null,
"deadline": null
},
{
"id": "9469c0e4-148c-11e9-b673-005056be36b2",
"answer": "1",
"id_question": "10",
"pi": null,
"ca": null,
"pic": null,
"new_deadline": null,
"reason": null,
"notes": null,
"deadline": null
}
]
array_question 是:
[
{
"id": "10",
"question": "Shop sign/billboard"
},
{
"id": "11",
"question": "Pylon"
},
{
"id": "12",
"question": "Banner"
},
{
"id": "13",
"question": "Sport"
},
{
"id": "14",
"question": "Matic"
},
{
"id": "16",
"question": "Cub"
}
]
结果 (array_result) 是:
[
{
"id": "10",
"question": "Shop sign/billboard",
"answer":"1",
"pi": null,
"ca": null,
"pic": null,
"new_deadline": null,
"reason": null,
"notes": null,
"deadline": null
},
{
"id": "11",
"question": "Pylon",
"answer" : "1",
"pi": null,
"ca": null,
"pic": null,
"new_deadline": null,
"reason": null,
"notes": null,
"deadline": null
},
{
"id": "12",
"question": "Banner",
"answer": "3",
"pi": null,
"ca": null,
"pic": null,
"new_deadline": null,
"reason": null,
"notes": null,
"deadline": null
},
{
"id": "13",
"question": "Sport",
"answer" : null,
"pi": null,
"ca": null,
"pic": null,
"new_deadline": null,
"reason": null,
"notes": null,
"deadline": null
},
{
"id": "14",
"question": "Matic",
"answer": "3",
"pi": null,
"ca": null,
"pic": null,
"new_deadline": null,
"reason": null,
"notes": null,
"deadline": null
},
{
"id": "16",
"question": "Cub",
"answer" : null,
"pi": null,
"ca": null,
"pic": null,
"new_deadline": null,
"reason": null,
"notes": null,
"deadline": null
}
]
在我链接的示例中,array_answer 中只有 1 项输入到array_result,即answer,现在我想添加pi,ca,pic,deadline,@ 987654335@、reason 和 notes。我该怎么做?不明白,请帮帮我..
谢谢你..
【问题讨论】:
-
您的数组问题是无效的 json,因为它到处都是印刷/智能引号 (
”),而不是它们应该是中性/直引号 (") - 例如“Cub”应该是"Cub" -
我已经编辑了我的 array_question @lovelace
-
您是否编辑了
”的所有出现,因为有很多(cub 只是一个示例) - 如果 json 包含无效字符,您的 json_decode() 将返回 NULL,这可能解释(部分)您的问题。 -
是的,我已经全部编辑了
标签: php arrays json array-merge