-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.4] array_random helper #19741
[5.4] array_random helper #19741
Conversation
return $array[array_rand($array)]; | ||
} | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably support the optional $num
argument as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the $num
argument should be supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, just as a proposal: in addition to the regular "raffle tickets" mode, a "dice roll" mode might be added, allowing items to be picked several times. (see fzaninotto/Faker#1060 to better understand what I mean)
Nice work! And what about docs? The are few functions in src/Illuminate/Support/helpers.php, but not in the docs. Or will documentation be updated with laravel 5.5? |
I know helper functions are unlikely to be pulled in, but figured I'd at least mention this. (I did include a usage of this helper in the framework FWIW)
I use this personally (especially in testing contexts).
The all to common pattern that makes me feel a little bit bad every time:
same thing with new helper:
much cleaner IMO - let's see what you think though
Thanks as always!