Search

Showing 7 of 587 result(s)

/blog/2018/04/22/laravel-5-collections-pair-the-values-of-a-collection-with-the-values-of-other-collections-with-zip

The zip method is used to merge the values of two collections. The first collection will be the collection that the zip method was invoked on, the second collection is supplied as an argument. The zip method produces results that are similar to...

/blog/2018/04/22/laravel-5-collections-randomizing-element-order-with-shuffle

The shuffle method is used to rearrange the items of the array in a random distribution. The shuffle method will return a new collection and will not modify the original collection instance.The following code example shows the usage of the shuffle...

/blog/2018/04/22/laravel-5-collections-reducing-a-collection-to-one-element-with-reduce

The reduce method is to reduce a collection into only one item. It does this by iterating over the collection and applying the $callback function on each element. The $callback function should define two parameters: $carry and $item . The $carry...

/blog/2018/04/22/laravel-5-collections-retrieving-a-subset-of-a-collections-elements-with-only

The only method is the logical opposite of the except method. The only method is used to return all the key/value pairs in the collection where the keys in the collection are in the supplied $keys array. If the argument supplied for $keys...

/blog/2018/04/22/laravel-5-collections-retrieving-and-removing-the-last-collection-element-with-pop

The pop method is used to retrieve the last item from the collection while also removing it from the collection. If there are no items in the collection, the pop method will return null . The pop method modifies the collection instance it is...

/blog/2018/04/22/laravel-5-collections-retrieving-the-collection-elements-keys-with-keys

The keys method is used to retrieve the keys of all items in the collection. The keys method returns a new Collection instance. The behavior of the keys method is similar to PHP's array_keys function.public function keys();The following code...

/blog/2018/04/22/laravel-5-collections-retrieving-the-distinct-values-of-a-collection-with-unique

The unique method can be used to get all the unique items in the collection. It accepts an optional $key argument which can be used to further restrict which items are returned. The unique method returns a new instance of Collection with the items...