Upgrade to 4.4.0
This commit is contained in:
@@ -738,12 +738,18 @@ class A
|
||||
/**
|
||||
* Returns a number of random elements from an array,
|
||||
* either in original or shuffled order
|
||||
*
|
||||
* @throws \Exception When $count is larger than array length
|
||||
*/
|
||||
public static function random(
|
||||
array $array,
|
||||
int $count = 1,
|
||||
bool $shuffle = false
|
||||
): array {
|
||||
if ($count > count($array)) {
|
||||
throw new InvalidArgumentException('$count is larger than available array items');
|
||||
}
|
||||
|
||||
if ($shuffle === true) {
|
||||
return array_slice(self::shuffle($array), 0, $count);
|
||||
}
|
||||
|
Reference in New Issue
Block a user