Grouping array_column results

php.internals

Hassan Ahmed

4 years ago
Hello, I started to edit the array_column function to accept the fourth parameter to group the similar results The current behavior is when you have multiple elements share the same key, it will be overwritten. let's assume that we have the following. ``` <?php $array = [ ['id' => 1, 'name' => 'hassan'], ['id' => 2, 'name' => 'sara'], ['id' => 3, 'name' => 'selim'], ['id' => 4, 'name' => 'chris'], ['id' => 5, 'name' => 'sara'], ]; ``` when we use array_column with this the output will be ``` print_r(array_column($array, null, 'name')); Array ( [hassan] => Array ( [id] => 1 [name] => hassan ) [sara] => Array ( [id] => 5 [name] => sara ) [selim] => Array ( [id] => 3 [name] => selim ) [chris] => Array ( [id] => 4 [name] => chris ) ) ``` I'd added a fourth parameter to array_column to group the results in an indexed array to group all the similar elements, so we can use : ``` print_r(array_column($array, null, 'name', true)); Array ( [hassan] => Array ( [0] => Array ( [id] => 1 [name] => hassan ) ) [sara] => Array ( [0] => Array ( [id] => 2 [name] => sara ) [1] => Array ( [id] => 5 [name] => sara ) ) [selim] => Array ( [0] => Array ( [id] => 3 [name] => selim ) ) [chris] => Array ( [0] => Array ( [id] => 4 [name] => chris ) ) ) ``` not sure if we need to implement this as a new function `array_column_group` or we can keep the fourth optional parameter. however, I have an issue in creating an account on the wiki so I can not create an RFC. it keeps giving me this error `That wasn't the answer we were expecting` no matter the email/user name I use PR number: https://github.com/php/php-src/pull/7698

Christoph Becker

4 years ago
On 28.11.2021 at 09:16, Hassan Ahmed wrote:
> however, I have an issue in creating an account on the wiki so I can > not create an RFC. > > it keeps giving me this error `That wasn't the answer we were > expecting` no matter the email/user name I use
You need to enter the address of this mailing list in the last input field. :)
-- Christoph M. Becker

Hassan Ahmed

4 years ago
Hello Christoph, Thanks for your reply, I already created the account and now waiting for the account confirmation. Thanks a lot. On Sun, Nov 28, 2021 at 12:46 PM Christoph M. Becker <cmbecker69@gmx.de> wrote:

Christoph Becker

4 years ago
On 28.11.2021 at 12:06, Hassan Ahmed wrote:
> Hello Christoph, Thanks for your reply, I already created the account > and now waiting for the account confirmation. Thanks a lot.
RFC karma granted. Best of luck! :) Christoph

Hassan Ahmed

4 years ago
Thanks a lot for your support. On Sun, Nov 28, 2021 at 1:18 PM Christoph M. Becker <cmbecker69@gmx.de> wrote:

Hassan Ahmed

4 years ago
Hello Christoph, does there any way to update my username from `7snovic` to `hassan` ? On Sun, Nov 28, 2021 at 1:38 PM Hassan Ahmed <7snovic@gmail.com> wrote:

Christoph Becker

4 years ago
On 28.11.2021 at 13:21, Hassan Ahmed wrote:
> Hello Christoph, does there any way to update my username from > `7snovic` to `hassan` ?
Done. Also, please note that top posting is frowned upon on the PHP mailing lists, see <https://github.com/php/php-src/blob/master/docs/mailinglist-rules.md>. :) Christoph