Search

Showing 7 of 1,216 result(s)

/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-into-a-collection-of-keyarray-value-pairs-with-maptodictionary

In computing, a dictionary is a data structure where there exists a relationship between a single key and a value, or a list multiple values; examples of these are associative arrays and maps (both of which are easily implemented with PHP arrays)....

/blog/2018/04/22/laravel-5-collections-reducing-a-collection-into-a-collection-of-keycollection-value-pairs-with-maptogroups

The mapToGroups method is similar to the mapToDictionary method, in that the mapToGroups method allows you take a collection of data and reduce it such that the final result is a collection of key/value pairs. The resulting value for each key may...

/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-reducing-a-collection-with-user-defined-keys-with-mapwithkeys

The mapWithKeys is similar to the mapToDictionary and mapToGroups methods in that it accepts a $callback function that defines an association between the returned key and value. The mapWithKeys method does not change the original collection; it...

/blog/2018/04/22/laravel-5-collections-reducing-a-multi-dimensional-collection-to-a-single-dimension-losing-keys-with-flatten

The flatten method will return a new Collection instance representing a flattened version of the original collection's items. The flatten method internally makes use of the "Illuminate\Support\Arr::flatten($array)" helper method. The flatten...

/blog/2018/04/22/laravel-5-collections-removing-a-portion-of-a-collection-with-splice

The splice method is a useful method; it is often used to remove a portion of a collection and return the removed section. It defines three parameters: $offset , $length and $replacement . The $offset tells the splice method where to begin when...