File tree 3 files changed +33
-0
lines changed
3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,10 @@ echo $collection->get('user_email');
78
78
79
79
Creates an instance of ` Collection ` . Optionally pass an associative array for ` $items ` to prefill the collection with items.
80
80
81
+ ##### ` static make(...$arrays) : Collection `
82
+
83
+ Make a collection from one or more arrays.
84
+
81
85
##### ` set(string $key, mixed $value) : void `
82
86
83
87
Add an item to the collection. If ` $key ` already exists in the collection it will be overwritten.
Original file line number Diff line number Diff line change @@ -57,6 +57,21 @@ public function __unset($key)
57
57
///////////////////////////////////
58
58
// Collection Methods
59
59
60
+ /**
61
+ * Make a collection from one or more arrays.
62
+ *
63
+ * @param array ...$arrays
64
+ * @return Collection
65
+ */
66
+ public static function make (array ...$ arrays ): Collection
67
+ {
68
+ $ items = [];
69
+ foreach ($ arrays as $ arr ) {
70
+ $ items += $ arr ;
71
+ }
72
+ return new self ($ items );
73
+ }
74
+
60
75
/**
61
76
* Add an item to the collection.
62
77
*
Original file line number Diff line number Diff line change @@ -67,6 +67,20 @@ public function isNotCollectionItemsProvider()
67
67
///////////////////////////////////
68
68
// Tests
69
69
70
+ /**
71
+ * @covers Collection::make
72
+ */
73
+ public function testMake ()
74
+ {
75
+ $ items_1 = ['key1 ' => 'val1 ' ];
76
+ $ items_2 = ['key2 ' => 'val2 ' ];
77
+ $ items_3 = ['key3 ' => 'val3 ' ];
78
+ $ collection = Collection::make ($ items_1 , $ items_2 , $ items_3 );
79
+ $ this ->assertTrue ($ collection ->has ('key1 ' ));
80
+ $ this ->assertTrue ($ collection ->has ('key2 ' ));
81
+ $ this ->assertTrue ($ collection ->has ('key3 ' ));
82
+ }
83
+
70
84
/**
71
85
* @covers Collection::count
72
86
*/
You can’t perform that action at this time.
0 commit comments