-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Wildcard support for array_get #1134
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
Conversation
This is quite complicated. Does underscore.php or some other lib already offer this? |
@taylorotwell, no idea. I've checked google before starting to write this thing, but haven't found anything adequate (mostly when it comes to search it's about searching for keys/values with wildcard). Which underscore? Underscore.php? |
This is cool, quite cool. But, as Otwell said, does underscore already handle this? I'd also be interested on the performance implications on non wildcard arrays |
@bencorlett, don't think performance should be an issue. There's an if clause run on every key segment which checks if current segment is a wildcard. So, if it's a non wildcard key (i assume you meant that?) it should run maybe tiny little bit slower then current array_get. I'll add benchmarks later. Checked Underscore.php (link above), but haven't found anything similar. |
I think we might want to implement this as a different method separate from array_get. I do think it's a pretty nifty method, but it adds quite a bit of complexity to the array_get function. |
Sure. I guess since array_get is one of the most used functions across the
|
Yeah it is used quite a bit since it used by configuration, etc. |
@bencorlett, ok, made a little benchmark to see the difference in speed between array_get with wildcard support and without. Tested on an Atom-powered netbook.
array_get($array, 'users.0.name'); Loop with 1000 iterations: 0.02089 s array_get($array, 'users.*.name');
// will return array containing two names! Loop with 1000 iterations: 0.04872 s
array_get($array, 'users.0.name'); Loop with 1000 iterations: 0.01531 s So, difference between 1000 iteration of And about name. Maybe |
array_select maybe? |
Go to sleep Taylor! Lol Sent from my iPhone On 14/05/2013, at 4:18 PM, Taylor Otwell notifications@github.com wrote:
|
I like. Sent from my iPhone On 14/05/2013, at 4:18 PM, Taylor Otwell notifications@github.com wrote:
|
Huh. Found myself trying to use wildcard with Input::get('*.body'); I'm thinking maybe keep it in array_get instead of renaming? I think performance trade off is pretty reasonable (~6ms or less on netbook running 10k iterations) considering functionality that thing adds. Besides that, without renaming it'll be immediately available for use with Input, File, Config and other calls |
This is just too nasty honestly. Feel free to implement in a Gist or a package or something. |
@taylorotwell, hah, yes it is nasty indeed. But, alas, some things are just nasty, especially when it comes to recursion. I guess since #1340, is based off of that, i should close it too. |
This is something that I currently need for my project. If you don't mind, could you make a package out of it? |
@fadillzzz, do you need it as part of the Core? If not, you might want to just copy/paste function into |
@KaneCohen Nah, not really. In fact, I've just extended the Validator class and created a pretty short validation method that solves my problem. I think I'll just roll with that instead. |
@fadillzzz, added validation class with wildcard support to packagist. |
@KaneCohen heheh, didn't expect that you'd do it anyway. Thanks though, I might just fiddle around with it. |
@fadillzzz, no problem. I thought of adding it anyway, just haven't had enough initiative for that. |
[9.x] Default Redis cache connection is wrong
Add ability to fetch items from the array with wildcard "*".
Example in the picture (and in the test).