【发布时间】:2016-02-25 00:37:39
【问题描述】:
我已经尝试了几个星期来让它工作,并且已经放弃了。我需要在 JSON 中显示以下数组。
如您所见,[coloroptions] 本身就是一个 JSON 数组,使其成为一个多维数组。诀窍是(我认为)迭代数组,首先在子 [coloroptions] 上,然后在父级上。不过,我可能离基地很远。有人做过这样的事吗?
提前谢谢你!
样本数据来自 print_r()
Array
(
[0] => Array
(
[id] => 1
[automobile] => 'Mustang'
[coloroptions] => [{"color":"red"},{"color":"blue"},{"color":"green"}]
)
[1] => Array
(
[id] => 2
[automobile] => 'Camero'
[coloroptions] => [{"color":"red"},{"color":"orange"}]
)
)
JSON 输出
[
{
"id": 1,
"automobile": "Mustang",
"color": "red"
},
{
"id": 1,
"automobile": "Mustang",
"color": "blue"
},
{
"id": 1,
"automobile": "Mustang",
"color": "green"
},
{
"id": 2,
"automobile": "Camero",
"color": "red"
},
{
"id": 2,
"automobile": "Camero",
"color": "orange"
},
]
【问题讨论】:
-
“JSON 输出”是所需的输出吗?
-
是的,示例中的 JSON 是我试图通过提供的数据实现的。该项目更深入,但对如何处理它有基本的了解,会让我朝着正确的方向前进。非常感谢!
标签: php arrays json multidimensional-array