Upgrade to 3.6.6

This commit is contained in:
Bastian Allgeier
2022-05-05 13:58:33 +02:00
parent 5c64df9e2b
commit d515908e2e
12 changed files with 190 additions and 24 deletions

View File

@@ -870,6 +870,25 @@ class Collection extends Iterator implements Countable
return $result;
}
/**
* Returns a new collection consisting of random elements,
* from the original collection, shuffled or ordered
*
* @param int $count
* @param bool $shuffle
* @return static
*/
public function random(int $count = 1, bool $shuffle = false)
{
if ($shuffle) {
return $this->shuffle()->slice(0, $count);
}
$collection = clone $this;
$collection->data = A::random($collection->data, $count);
return $collection;
}
/**
* Removes an element from the array by key
*