File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
Expand file tree Collapse file tree 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');
7878
7979Creates an instance of ` Collection ` . Optionally pass an associative array for ` $items ` to prefill the collection with items.
8080
81+ ##### ` static make(...$arrays) : Collection `
82+
83+ Make a collection from one or more arrays.
84+
8185##### ` set(string $key, mixed $value) : void `
8286
8387Add 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)
5757 ///////////////////////////////////
5858 // Collection Methods
5959
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+
6075 /**
6176 * Add an item to the collection.
6277 *
Original file line number Diff line number Diff line change @@ -67,6 +67,20 @@ public function isNotCollectionItemsProvider()
6767 ///////////////////////////////////
6868 // Tests
6969
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+
7084 /**
7185 * @covers Collection::count
7286 */
You can’t perform that action at this time.
0 commit comments