Search

Showing 7 of 1,697 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-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-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-collection-elements-at-a-specific-interval-with-nth

The nth method returns a new collection containing the elements of the original collection that appear at the $step interval (for example, give me every third element within the collection). An $offset may also be specified to indicate which index...

/blog/2018/04/22/laravel-5-collections-retrieving-collection-elements-whose-keys-are-not-present-in-the-provided-keys-with-diffkeys

The diffKeys method is similar to the diff method. It is used to determine which items whose keys in the collection are not present in the supplied $items collection's keys. $items can be either an array, or another instead of Collection .The...

/blog/2018/04/22/laravel-5-collections-retrieving-the-maximum-value-of-a-collection-with-max

The max method can be used to retrieve the maximum value of the given $key . By default, the $key is null and will function in a similar way to PHP's max function.The following code example highlights the usage of max without specifying a $key :...

/blog/2018/04/22/laravel-5-collections-sort-a-collection-in-descending-order-with-sortbydesc#content-using-sortbydesc-with-higher-order-messages

Like the sortBy method, the sortByDesc method can also be used with higher order messages. We will adjust the example explored in the sortBy section: The PeripheralDevice Class: sortByDesc with Higher Order Messages: After the above code has...