-
Notifications
You must be signed in to change notification settings - Fork 7.8k
add ability to use array keys with array_filter() #287
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
+1, it would really simplify my life :) shouldn't the example provided return [5, 6, 7]? |
@davidkuridza That's if array keys were 1-indexed :) |
of course, stupid me :) |
Tested on windows, it's ok (except see the comment about the test). Another thing - actually the third arg isn't needed, you could just pass two args to the func by default. If the filter callback has only one arg in the signature, so the second is just ignored. That means the older code is still compatible while no need to add the third arg to the array_filter signature. |
@weltling I've discussed dropping the third arg on the mailing list; basically, functions with optional arguments may start to break if we always send the key. |
True, passing two args unconditionally is a BC breach, sigh! The test is ok now, also all the other array_filter_* tests pass. Good work! |
@weltling Great! I'm a bit new with this, do I close the pull request? |
May be someone else will take a look yet. Please wait until it's merged then. The person who merges it will close it. |
Thanks for your patience. Things aren't always going as fast as hoped for :/. This thread is stalled atm :/. Can you resend a list to the ML and ping me back in 2 weeks? If there are no objections, I would like to have that change and I don't think an RFC is necessary (even though people might disagree), but I would like to see it being discussed before merging it into master. |
Can we have the bitmask option? I like it best. |
Merged to master, you can close this now |
@srgoogleguy It looks to me as if there's a piece missing. It doesn't seem to actually define |
@TazeTSchnitzel If you followed the discussion on Internals you should know that the implementation has changed to not define an ARRAY_FILTER_USE_VALUE constant, since this is the default behavior anyway. It doesn't make much sense to define a constant for behavior the function does regardless of the argument supplied. See http://news.php.net/php.internals/69341 You were probably looking at https://github.com/php/php-src/pull/287/files#diff-9a4220f442d2acbb4519beb4481d13e9R5 which mentions the constant name in the test file comment. Admittedly this may confuse a few folks. Perhaps we should delete that comment as not to confuse anyone for now. |
And this is why I don't like documenting my code ;-) |
This adds a third (optional) argument to
array_filter()
that will determine what gets passed to the callback, the array key, value or both.