29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Collections 224<br />

.<br />

1 $collection = collect([<br />

2 ['product' => 'Desk', 'price' => 200],<br />

3 ['product' => 'Chair', 'price' => 100],<br />

4 ['product' => 'Bookcase', 'price' => 150],<br />

5 ['product' => 'Door', 'price' => 100],<br />

6 ]);<br />

7<br />

8 $filtered = $collection->where('price', 100);<br />

9<br />

10 $filtered->all();<br />

11<br />

12 /*<br />

13 [<br />

14 ['product' => 'Chair', 'price' => 100],<br />

15 ['product' => 'Door', 'price' => 100],<br />

16 ]<br />

17 */<br />

The where method uses strict comparisons when checking item values. Use the whereLoose method<br />

to filter using “loose” comparisons.<br />

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

This method has the same signature as the where method; however, all values are compared using<br />

“loose” comparisons.<br />

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

The zip method merges together the values of the given array with the values of the collection at<br />

the corresponding index:<br />

.<br />

1 $collection = collect(['Chair', 'Desk']);<br />

2<br />

3 $zipped = $collection->zip([100, 200]);<br />

4<br />

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

6<br />

7 // [['Chair', 100], ['Desk', 200]]

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

Saved successfully!

Ooh no, something went wrong!