Showing 7 of 1,697 result(s)
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...
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...
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...
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...
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...
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 :...
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...