Skip to content
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

Merged
merged 3 commits into from
Jun 23, 2017
Merged

Conversation

calebporzio
Copy link
Contributor

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:

return $array[array_rand($array)];

same thing with new helper:

return array_random($array);

much cleaner IMO - let's see what you think though

Thanks as always!

@calebporzio calebporzio changed the title array_random helper [5.4] array_random helper Jun 23, 2017
return $array[array_rand($array)];
}

/**
Copy link
Contributor

@tillkruss tillkruss Jun 23, 2017

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

Copy link
Contributor

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.

Copy link
Contributor

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)

@taylorotwell taylorotwell merged commit 75554ce into laravel:5.4 Jun 23, 2017
@nicklasos
Copy link

nicklasos commented Jun 26, 2017

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants