讓我真的很快得到這個,這是我的源陣列:現有陣列中創建兒童
Array (
[0] => Array (
[1] => Array (
[id] => 1
[category] => Men
[items] => Array (
[0] => Array (
[id] => 1
[name] => Shirt
[price] => 21.8
)
)
)
)
[1] => Array (
[1] => Array (
[id] => 2
[category] => Men
[items] => Array (
[0] => Array (
[id] => 2
[name] => Trousers
[price] => 10.9
)
)
)
)
[2] => Array (
[1] => Array (
[id] => 3
[category] => Men
[items] => Array (
[0] => Array (
[id] => 3
[name] => Hat
[price] => 1.9
)
)
)
)
[3] => Array (
[2] => Array (
[id] => 4
[category] => Women
[items] => Array (
[0] => Array (
[id] => 4
[name] => Bra
[price] => 24.5
)
)
)
)
.
.
.
我想現在實現的是通過類似category
這樣的結合items
:
{
"1": {
"id": 1,
"category": "Men",
"items": [
{
"id": 1,
"name": "Shirt",
"price": "5:52"
},
{
"id": 2,
"name": "Trousers",
"price": "3:01"
},
]
},
.
.
.
我已經嘗試了幾種方法與parentId和東西,但無法繞過它。
任何想法如何得到這個?
謝謝!這一個真的有用。價格值只是虛擬的,不需要擔心:) – AimanB