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.

Helper Functions 269<br />

.<br />

1 $array = ['products' => ['desk' => ['price' => 100]]];<br />

2<br />

3 array_forget($array, 'products.desk');<br />

4<br />

5 // ['products' => []]<br />

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

The array_get method retrieves a value from a deeply nested array using “dot” notation:<br />

.<br />

1 $array = ['products' => ['desk' => ['price' => 100]]];<br />

2<br />

3 $value = array_get($array, 'products.desk');<br />

4<br />

5 // ['price' => 100]<br />

The array_get function also accepts a default value, which will be returned if the specific key is not<br />

found:<br />

.<br />

1 $value = array_get($array, 'names.john', 'default');<br />

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

The array_only method will return only the specified key / value pairs from the given array:<br />

.<br />

1 $array = ['name' => 'Desk', 'price' => 100, 'orders' => 10];<br />

2<br />

3 $array = array_only($array, ['name', 'price']);<br />

4<br />

5 // ['name' => 'Desk', 'price' => 100]<br />

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

The array_pluck method will pluck a list of the given key / value pairs from the array:

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

Saved successfully!

Ooh no, something went wrong!