29.07.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Collections 201<br />

.<br />

1 $collection = collect(['name' => 'taylor', 'languages' => ['php', 'javascript']]\<br />

2 );<br />

3<br />

4 $flattened = $collection->flatten();<br />

5<br />

6 $flattened->all();<br />

7<br />

8 // ['taylor', 'php', 'javascript'];<br />

flip() {#collection-method}<br />

The flip method swaps the collection’s keys with their corresponding values:<br />

.<br />

1 $collection = collect(['name' => 'taylor', 'framework' => '<strong>laravel</strong>']);<br />

2<br />

3 $flipped = $collection->flip();<br />

4<br />

5 $flipped->all();<br />

6<br />

7 // ['taylor' => 'name', '<strong>laravel</strong>' => 'framework']<br />

forget() {#collection-method}<br />

The forget method removes an item from the collection by its key:<br />

.<br />

1 $collection = collect(['name' => 'taylor', 'framework' => '<strong>laravel</strong>']);<br />

2<br />

3 $collection->forget('name');<br />

4<br />

5 $collection->all();<br />

6<br />

7 // [framework' => '<strong>laravel</strong>']<br />

Note: Unlike most other collection methods, forget does not return a new modified<br />

collection; it modifies the collection it is called on.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!