我想把多个Collection 合并成一个.我有一个解决方案,如下所示:
$allItems = $collection1->merge($collection2)
->merge($collection3)
->merge($collection4)
->merge($collection5);
This actually does work, but I run into problems in cases where some or all of the collections contain no objects. I get an error along the lines of call to merge() on non object
.
I actually tried to create an array of all of the collections, and then iterate through them, while checking their validity, but it didn't work and I feel it wasn't very elegant.
How can I elegantly iterate through this process of merging multiple collections, while taking into account that some or all of the collections might be empty or invalid? Appreciated!