gpt4 book ai didi

php - 如何将数组的格式更改为集合作为 laravel 中的每个项目

转载 作者:行者123 更新时间:2023-11-29 02:09:11 25 4
gpt4 key购买 nike

我有一系列如下所示的集合:

array:9 [▼
0 => Collection {#990 ▶}
1 => Collection {#1109 ▶}
2 => Collection {#1221 ▶}
3 => Collection {#1331 ▶}
4 => Collection {#1442 ▶}
5 => Collection {#1554 ▶}
6 => Collection {#1664 ▶}
7 => Collection {#1775 ▶}
8 => Collection {#1887 ▶}
]

我想把它做成一个单一的集合,并将每个集合作为该集合的一项,现在我尝试的是 collect($f) 但我得到的结果如下:

Collection {#1443 ▼
#items: array:9 [▼
0 => Collection {#990 ▶}
1 => Collection {#1109 ▶}
2 => Collection {#1221 ▶}
3 => Collection {#1331 ▶}
4 => Collection {#1442 ▶}
5 => Collection {#1554 ▶}
6 => Collection {#1664 ▶}
7 => Collection {#1775 ▶}
8 => Collection {#1887 ▶}
]
}

现在我想知道如何制作这 1 个集合并将所有这 8 个集合作为该集合的项目,如下所示:

Collection {#990 ▼
#items: array:1 [▼
0 => RoomPricingHistory {#971 ▶}
1 => RoomPricingHistory {#971 ▶}
2 => RoomPricingHistory {#971 ▶}
3 => RoomPricingHistory {#971 ▶}
4 => RoomPricingHistory {#971 ▶}

]
}

谢谢

最佳答案

一旦你有了一个收藏集,你就可以使用flatten获取父集合中基础集合的所有元素。

collect($f)->flatten(1);

关于php - 如何将数组的格式更改为集合作为 laravel 中的每个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58766162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com