The name makes sense, but would likely be confused with extract()
http://us3.php.net/extract
On 6/25/2012 5:35 PM, Paul Dragoonis wrote:
What about array_extract ?
On Mon, Jun 25, 2012 at 9:31 PM, Aaron Holmes <aa...@aaronholmes.net
<mailto:aa...@aaronholmes.net>> wrote:
For what my .02 is worth, I imagine "plucking" an item out of an
array would not occur to a user-land developer as the proper
nomenclature for extracting all the values from an array with the
given key. At worst, this means many developers simply won't learn
about the function and continue to implement it in user-land.
When array_column was offered as the name, I immediately knew what
the purpose was, before checking the RFC.
On 6/25/2012 12:22 PM, Ben Ramsey wrote:
On 6/25/12 9:44 AM, Matthew Weier O'Phinney wrote:
On 2012-06-23, Stas Malyshev <smalys...@sugarcrm.com
<mailto:smalys...@sugarcrm.com>> wrote:
I'm open to changing or aliasing the name to
array_pluck(), if others
are in agreement.
I wouldn't know what "pluck" means here. "Column" is a
clear word with
established meaning. Let's not get too whimsical here.
Nothing whimsical about it at all, Stas. The definition is:
Take hold of (something) and quickly remove it from
its place; pick
and synonyms include "pull" and "gather".
As Ralph noted, "column" is overloaded, as it has
connotations dealing
with databases as well as tables, and arrays often
represent neither.
I agree with Tom and Ralph that we should look at what others
are doing and pick a similar name. After searching on "pluck,"
though, I'm getting mixed results on how pluck is used:
In Rails, it looks like pluck is used for the purpose that
I've created array_column, but it's used with ActiveRecord as
a way to pull a column of results from the database (much like
PDOStatement::fetchColumn). See here:
https://github.com/rails/rails/commit/a382d60f6abc94b6a965525872f858e48abc00de
However, in Prototype.js and Underscore.js, pluck seems behave
more like array_map() in PHP:
http://api.prototypejs.org/language/Enumerable/prototype/pluck/
http://documentcloud.github.com/underscore/#pluck
Nevertheless, it would technically have the same effect as the
"column" functionality, since calling that method/property in
Javascript simply returns the value of the property or result
of the method call.
Also, the Python community has recently discussed adding pluck
for lists:
https://groups.google.com/forum/?fromgroups#!topic/python-ideas/p9qtUzg9zsk
<https://groups.google.com/forum/?fromgroups#%21topic/python-ideas/p9qtUzg9zsk>
It looks like they already have some functionality that
implements similar behavior, though:
>>> stooges=[{'name': 'moe', 'age': 40}, {'name': 'larry',
'age': 50}, {'name': 'curly', 'age': 60}]
>>> names=[guy['name'] for guy in stooges]
>>> print names
['moe', 'larry', 'curly']
array_column/pluck in PHP would do the same:
$names = array_column($stooges, 'name');
If other languages/frameworks/libraries are using pluck to
mean exactly what this implementation means, then I agree with
changing the name to array_pluck, but if "pluck" also carries
meaning similar to array_map, then I don't want to confuse folks.
-Ben
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php