Skip to content
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

Functionality updates to array_column() #331

Closed
wants to merge 3 commits into from
Closed

Functionality updates to array_column() #331

wants to merge 3 commits into from

Conversation

ramsey
Copy link
Member

@ramsey ramsey commented Apr 22, 2013

This pull request updates the array_column() function to support the following new functionality:

  • Maintain original index association if no third parameter
  • Second param should be optional to use entire rows as result
  • Support array of column names for second parameter

This has been discussed on the #php.pecl IRC channel, and others agreed that these are good additions that can be added as this time, while 5.5 is still in beta. Once 5.5 moves to RC or GA, these features would present possible BC breaks to the array_column() functionality and should not be added.

Here are more detailed descriptions of the additional functionality:

Maintain original index association if no third parameter

If no third parameter is passed, the resulting array maintains the indexes passed in from the original array. Feature suggested by David Zülke.

Second param should be optional to use entire rows as result

When NULL is passed as the second parameter, all columns from the input array are returned. See https://bugs.php.net/bug.php?id=64493

Support array of column names for second parameter

If the second parameter is an array of column names, each row returned in the result array is an array containing only the specified columns. The rows are indexed by the third parameter. Feature inspired by suggestions from Hakre and Craig Campbell. See #257 (comment)

If no third parameter is passed, the resulting array maintains the
indexes passed in from the original array. Feature suggested by David
Zülke.
When NULL is passed as the second parameter, all columns from the input
array are returned. See https://bugs.php.net/bug.php?id=64493
If the second parameter is an array of column names, each row returned
in the result array is an array containing only the specified columns.
The rows are indexed by the third parameter. Feature inspired by
suggestions from Hakre and Craig Campbell. See
#257 (comment)
@Marat-Tanalin
Copy link

Current design of the third feature ("Support array of column names for second parameter") looks like suboptimal.

What if web developer needs to narrow-down resulting columns and use one of other columns for keys of new rows at the same time?

I believe this third feature should be implemented as additional (4th) parameter and in no way should be shared with second parameter that has its own different purpose, and having arbitrary column for resulting keys is not mutually exclusive with ability to narrow-down resulting columns. This will ensure clarity, flexibility, and usefulness of the function. Thanks.

@bukka
Copy link
Member

bukka commented Apr 22, 2013

There also is one small thing that could be addressed. It's not a big bug but -1 cannot be currently used in the key column. See http://3v4l.org/fT1th . I sent a pull request few weeks ago so you can use it if you want... #317

@ramsey
Copy link
Member Author

ramsey commented Jul 6, 2013

Closing this. After discussion, it was decided not to merge this into core.

@ramsey ramsey closed this Jul 6, 2013
@ramsey ramsey deleted the feature-array_column-updates branch July 6, 2013 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants