By John Koster
The concat method will create a new collection by combining the values of the collection instance is called on with the provided $source. It is important to note that the source must implement the Traversable interface.
The concat method does not modify the original collection instance, and it will return a new collection instance containing the concatenated items.
#Signature
1public function concat(
2 $source
3);
#Example Use
The following example demonstrates the basic usage of the concat method:
1$collectionOne = collect([
2 'first',
3 'second',
4 'third'
5]);
6
7$collectionTwo = $collectionOne->concat([
8 'third',
9 'fourth',
10 'fifth'
11]);
After the above example has executed, the $collectionTwo variable will contain the following items:
| Index | Value |
|---|---|
| 0 | first |
| 1 | second |
| 2 | third |
| 3 | third |
| 4 | fourth |
| 5 | fifth |
∎