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.

Helper Functions 268<br />

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

The array_first method returns the first element of an array passing a given truth test:<br />

.<br />

1 $array = [100, 200, 300];<br />

2<br />

3 $value = array_first($array, function ($key, $value) {<br />

4 return $value >= 150;<br />

5 });<br />

6<br />

7 // 200<br />

A default value may also be passed as the third parameter to the method. This value will be returned<br />

if no value passes the truth test:<br />

.<br />

1 $value = array_first($array, $callback, $default);<br />

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

The array_flatten method will flatten a multi-dimensional array into a single level.<br />

.<br />

1 $array = ['name' => 'Joe', 'languages' => ['PHP', 'Ruby']];<br />

2<br />

3 $array = array_flatten($array);<br />

4<br />

5 // ['Joe', 'PHP', 'Ruby'];<br />

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

The array_forget method removes a given key / value pair from a deeply nested array using “dot”<br />

notation:<br />

.

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

Saved successfully!

Ooh no, something went wrong!