-
Notifications
You must be signed in to change notification settings - Fork 327
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
Added function Arr::extract_existing() #369
base: 3.4/develop
Are you sure you want to change the base?
Conversation
Similar to extract except that it doesnt return keys that arnt set in the first array. EX.. Arr::filter( array('a' => 'foo', 'b' => 'bar'), array('a','c') ); Returns array('a' => 'foo') Key b is removed from results altogether. This is particularly useful for extracting fields from $_POST for Model without leaveing unset values as NULL. Regular extract in this situation will end up saving value "C" above as NULL even if your only attempting to change "A".
Did you ever make a redmine ticket for this? |
Bit of a mouthful, Underscore calls this pick. You could rewrite the method to: array_intersect_key($arr, array_flip($keys)) But this won't work on objects that implement |
Thanks for this @danieliser. No need for a Redmine ticket anymore, but definitely unit tests :) |
Also, I think the method name needs to change, but I am not sure. |
Agreed, i thought of several names since. Glad to see this finally make it into core. Hell glad to see that project isn't dead. Felt like community died shortly after i started using Kohana heavily. |
I like this, missing tests, should be for 4.0.0? |
Similar to extract except that it doesnt return keys that arnt set in the first array.
EX..
Arr::filter(
array('a' => 'foo', 'b' => 'bar'),
array('a','c')
);
Returns array('a' => 'foo')
Key b is removed from results altogether.
This is particularly useful for extracting fields from $_POST for Model without leaveing unset values as NULL.
Regular extract in this situation will end up saving value "C" above as NULL even if your only attempting to change "A".