独特的收藏Laravel
知道如何在这个Laravel集合中不同的价值
想
我 因此,我可以在集合中使其独特而沮丧的值
这就是我的理解方式:
$CategorieTree = $CategoriesItineraires->map(function ($categorie) {
return (object) [
$categorie->categorie->map(function ($items) {
return $items;
})
];
});
这就是结果!
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => stdClass Object
(
[0] => Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => Fongicides et assimilés
)
)
)
[1] => stdClass Object
(
[0] => Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => Autres
)
)
)
[2] => stdClass Object
(
[0] => Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => Insecticides et assimilés
[1] => Fongicides et assimilés
)
)
)
[3] => stdClass Object
(
[0] => Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => Autres
)
)
)
)
)
I wonder how to distinct values in this Laravel collection because there is sub array of objects
There is too much sub-arrays, but i don't know how to filter this collection to get less sub-arrays
I wish to get less sub-arrays so i could make it unique and disctinct values within the collection
This is how i get this :
$CategorieTree = $CategoriesItineraires->map(function ($categorie) {
return (object) [
$categorie->categorie->map(function ($items) {
return $items;
})
];
});
This is the result !
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => stdClass Object
(
[0] => Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => Fongicides et assimilés
)
)
)
[1] => stdClass Object
(
[0] => Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => Autres
)
)
)
[2] => stdClass Object
(
[0] => Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => Insecticides et assimilés
[1] => Fongicides et assimilés
)
)
)
[3] => stdClass Object
(
[0] => Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => Autres
)
)
)
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Laravel收藏品有很多选项
我认为您正在寻找 flatten
除了您应该更改代码,第一个
返回对象[...]
给出了一个奇怪的结果。我认为您想要以下内容:
编辑:
可以缩短到:
Laravel collections have a lot of options
I think you're looking for flatten
Besides that you should change your code a little bit, the first
return object [...]
gives a weird result.I think you want the following:
Edit:
That can be shortened to: