rfc:array_column_results_grouping

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
rfc:array_column_results_grouping [2021/11/28 11:38] – created 7snovicrfc:array_column_results_grouping [2022/01/14 17:10] (current) – RFC has been declined cmb
Line 1: Line 1:
-====== PHP RFC: array_column results grouping ====== +====== PHP RFC: Add array_group function ====== 
-  * Version: 1.0+  * Version: 2.0
   * Date: 2021-11-28   * Date: 2021-11-28
   * Author: Hassan Ahmed, 7snovic@gmail.com   * Author: Hassan Ahmed, 7snovic@gmail.com
-  * Status: Draft+  * Status: Declined
   * First Published at: https://wiki.php.net/rfc/array_column_results_grouping   * First Published at: https://wiki.php.net/rfc/array_column_results_grouping
  
 ===== Introduction ===== ===== Introduction =====
-array_column ignores the duplicated rows for each similar columnt/index.+This RFC is to implement a new function to PHP that upgrades the functionality of array_column to group similar results that share the same index_key into a multidimensional array. the current behavior of array_column is to return a single result and ignore the rest of the results that share the same index.
  
 ===== Proposal ===== ===== Proposal =====
-This RFC is adding a new boolean parameter to array_column to determine it'behaviour of grouping or not +This RFC is to add a new function called array_group 
 +<code php>array_group(array $array, int|string|null $column_key, int|string|null $index_key = null)</code> 
 + 
 +The current behavior is when you have multiple elements share the same key, it will be overwritten. 
 +let'assume that we have the following.
  
 <code php> <code php>
-array_column(array $array, int|string|null $column_keyint|string|null $index_key null$grouping null): array+<?php 
 + 
 +$array = [ 
 +    ['id' => 1'name' => 'hassan'], 
 +    ['id' => 2'name' => 'sara'], 
 +    ['id' => 3, 'name' => 'selim'], 
 +    ['id' => 4, 'name' => 'chris'], 
 +    ['id' => 5, 'name' => 'sara'], 
 +];
 </code> </code>
  
-Or we can implement it as a new function with something like +when we use array_column with this the output will be
-<code php>array_column_group(array $array, int|string|null $column_key, int|string|null $index_key = null)</code>+
  
-And keep the same parameters.+<code php> 
 +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 
 +        ) 
 + 
 +
 +</code> 
 + 
 +The RFC implements a new function called array_group to group the results in an indexed array to group all the similar elements, so we can use : 
 + 
 +<code php> 
 +print_r(array_group($array, null, 'name')); 
 +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 
 +                ) 
 + 
 +        ) 
 + 
 +
 +</code>
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 32: Line 127:
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
-Include these so readers know where you are heading and can discuss the proposed voting options.+Yes/No vote. 
 + 
 +===== Voting ===== 
 + 
 +Started at : 2021-12-21 
 +Ends at : 2022-01-04 
 + 
 +<doodle title="Add array_group function to PHP" auth="hassan" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle>
  
 ===== Implementation ===== ===== Implementation =====
-[[https://github.com/php/php-src/pull/7698|Support grouping in array_column]]+[[https://github.com/php/php-src/pull/7698|Implementing array_group function]]
  
rfc/array_column_results_grouping.1638099489.txt.gz · Last modified: 2021/11/28 11:38 by 7snovic