我正在查询一个 API,它发送一个 JSON 响应,然后我将其解码为一个数组。这部分工作正常,但 API 以相当不友好的格式发送信息。
我将粘贴我遇到问题的部分。本质上,我正在尝试将每个类似的键更改为它们自己的数组。
Array
(
[name] => Name
[address] => 123 Street Rd
[products[0][product_id]] => 1
[products[0][price]] => 12.00
[products[0][name]] => Product Name
[products[0][product_qty]] => 1
[products[1][product_id]] => 2
[products[1][price]] => 3.00
[products[1][name]] => Product Name
[products[1][product_qty]] => 1
[systemNotes[0]] => Note 1
[systemNotes[1]] => Note 2
)
现在我想做的是让它像这样:
Array
(
[name] => Name
[address] => 123 Street Rd
[product] => Array
(
[0] => Array
(
[product_id] => 1
[price] => 12.00
[name] => Product Name
[product_qty] => 1
)
[1] => Array
(
[product_id] => 2
[price] => 3.00
[name] => Product Name
[product_qty] => 1
)
[systemNotes] => Array
(
[0] => Note 1
[1] => Note 2
)
)
有什么实用的方法可以做到这一点吗?
谢谢!