Hi all,
I've written a draft version of an RFC for pull request 56 (
https://github.com/php/php-src/pull/56 ), to add array_column()
to the
core. Please take a look and provide feedback so that I can improve the
patch/proposal.
https://wiki.php.net/rfc/array_column
Thanks,
Ben
Hi all,
I've written a draft version of an RFC for pull request 56 (
https://github.com/php/php-src/pull/56 ), to addarray_column()
to the core.
Please take a look and provide feedback so that I can improve the
patch/proposal.
I like your proposal and code examples on the RFC, this function is
useful and would save a foreach() to get the specified keys/indexes
out of the array.
- Paul.
Thanks,
Ben
Hi,
Shouldn't this be called 'array_pluck'?
This is the name people usually use when implementing it in PHP (see
"array_pluck(" vs "array_column(" in Google) or in other languages/libs (see
underscorejs, prototypejs and RoR).
--
Léo Peltier
Hi,
Shouldn't this be called 'array_pluck'?
This is the name people usually use when implementing it in PHP (see
"array_pluck(" vs "array_column(" in Google) or in other languages/libs
(see underscorejs, prototypejs and RoR).
I'm open to changing or aliasing the name to array_pluck(), if others
are in agreement.
-Ben
Hi,
Shouldn't this be called 'array_pluck'?
This is the name people usually use when implementing it in PHP (see
"array_pluck(" vs "array_column(" in Google) or in other languages/libs
(see underscorejs, prototypejs and RoR).I'm open to changing or aliasing the name to array_pluck(), if others are
in agreement.
+1 on using array_pluck.
The term 'column' makes a lot of sense for PDO working with database
columns, but there is no concept of a 'column' in the array structure or
PHP as a whole, outside of database related functions.
- Tom Sartain
The term 'column' makes a lot of sense for PDO working with database
columns, but there is no concept of a 'column' in the array structure or
PHP as a whole, outside of database related functions.
Actually, while perhaps most of the time a value from a column is what
people retrieving from a database result set, that is not always the
case. The result could be the value from an expression or a field from
a database view. Most database extensions outside of PDO do in fact
call it a "field", which I (too) feel is more appropriate.
In the case of this addition, I do indeed like array_pluck as well, as
column feel like an overloaded term.
-ralph
Hey Ben,
Hi,
Shouldn't this be called 'array_pluck'?
This is the name people usually use when implementing it in PHP (see
"array_pluck(" vs "array_column(" in Google) or in other languages/libs
(see underscorejs, prototypejs and RoR).I'm open to changing or aliasing the name to array_pluck(), if others are in agreement.
We have a version of this at Facebook and its called array_pull() it has a third parameter and supports pulling a new key value too. You can find a copy of it in Phabricator. There is also mpull() which is for methods. I'd recommend combining the two methods to be honest and doing a single function that supports index names or a method.
https://github.com/facebook/libphutil/blob/master/src/utils/utils.php#L143
- S
Hi!
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.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
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.
--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
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
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
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.
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
likearray_map()
in PHP:http://api.prototypejs.org/language/Enumerable/prototype/pluck/
http://documentcloud.github.com/underscore/#pluckNevertheless, 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
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
What about array_extract ?
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.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/*a382d60f6abc94b6a965525872f858
*e48abc00dehttps://github.com/rails/rails/commit/a382d60f6abc94b6a965525872f858e48abc00deHowever, in Prototype.js and Underscore.js, pluck seems behave more like
array_map()
in PHP:http://api.prototypejs.org/**language/Enumerable/prototype/**pluck/http://api.prototypejs.org/language/Enumerable/prototype/pluck/
http://documentcloud.github.**com/underscore/#pluckhttp://documentcloud.github.com/underscore/#pluckNevertheless, 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/p9qtUzg9zskhttps://groups.google.com/forum/?fromgroups#!topic/python-ideas/p9qtUzg9zskIt 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
The name makes sense, but would likely be confused with extract()
http://us3.php.net/extract
What about array_extract ?
On Mon, Jun 25, 2012 at 9:31 PM, Aaron Holmes <aaron@aaronholmes.net
mailto:aaron@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 2012-06-23, Stas Malyshev <smalyshev@sugarcrm.com <mailto:smalyshev@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