Skip to content

Implementing array_group function #7698

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

Closed
wants to merge 8 commits into from

Conversation

7snovic
Copy link
Contributor

@7snovic 7snovic commented Nov 28, 2021

@kaznovac
Copy link

nice feature :)

may i recommend for the 4th parameter to be more dynamic:

  • an option to preserve keys from the originating array (and use them as keys in new groups)
  • an option to use column value as a key in new groups

looking forward seeing this in core

@cmb69 cmb69 added the RFC label Nov 29, 2021
@7snovic 7snovic marked this pull request as draft November 29, 2021 13:55
@7snovic
Copy link
Contributor Author

7snovic commented Nov 30, 2021

@kaznovac Your first point is a good one, but I am not sure that I got your second one

@7snovic 7snovic force-pushed the array_column_group branch 3 times, most recently from 645f459 to 04e5982 Compare December 1, 2021 11:37
@7snovic
Copy link
Contributor Author

7snovic commented Dec 1, 2021

@cmb69 any clues why does this test case keeps failing?

@cmb69
Copy link
Member

cmb69 commented Dec 1, 2021

On AppVeyor, the test causes a segfault.

@7snovic 7snovic force-pushed the array_column_group branch from 04e5982 to 77dadf1 Compare December 3, 2021 14:19
@7snovic 7snovic marked this pull request as ready for review December 3, 2021 21:45
@ScSherifTarek
Copy link

I liked the idea @7snovic! and I think it's a good idea to have it as another function:

  1. As suggested by Uncle Bob in the clean code book, using flag parameters is not recommended.
  2. And to always expect a single structure for the result of the function.
  3. Also as @kaznovac suggested, the function could even grow to support more advanced features, having it as a separated function would make it more maintainable and gives us the flexibility we want.

@umairkhan-dev
Copy link

umairkhan-dev commented Dec 7, 2021

Sorry, but why the 4th parameter is bool|null, why not only bool?

From RFC:

array_column(array $array, int|string|null $column_key, int|string|null $index_key = null, $grouping = null): array

Why not,

array_column(array $array, int|string|null $column_key, int|string|null $index_key = null, bool $grouping = false): array

@7snovic 7snovic changed the title Support grouping in array_column Implementing array_group function Dec 12, 2021
@cmb69
Copy link
Member

cmb69 commented May 12, 2022

Since the respective RFC has been declined, I'm closing this ticket.

Thanks for your work nonetheless!

@cmb69 cmb69 closed this May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants