Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116578 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 178 invoked from network); 6 Dec 2021 21:16:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Dec 2021 21:16:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5AA681804A8 for ; Mon, 6 Dec 2021 14:16:56 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 6 Dec 2021 14:16:55 -0800 (PST) Received: by mail-qk1-f170.google.com with SMTP id t83so12734859qke.8 for ; Mon, 06 Dec 2021 14:16:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HuXEW/gEKeHWJZ9ipLHMgkkqj5qjCnkuC3BtU+8qHQA=; b=cWnZGYE05Rx/2iNETf84w8/599izNzf9hQvQXOFqmw3PhEMCORtLRhuU5r2jhpcRLb emQrJfe0nfztRmVHnGHI7nt4cqZ/9A1rNuOvxuqCyYRalATGwU7Jtb5KVi59etOuaQmJ im1S+aTG7CCdyEc3s4r5C3Tmj+c+sJsZbZIr1qSvS3Ba0H5JPR96SjfLE8Bfl1lWMuIE bPsp20mcM/oNOjSBhJdpxV2jejle6uIZsTbO/5h7hLFoedE/2vagMxMJqvSfmGcLofSv neEYoqlSFKoIvYf+RHdqGaJfkkZFXnKe98Cdo53ZvSdXOYt/1IJQogBKyWQsPg61ZCh9 KRig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HuXEW/gEKeHWJZ9ipLHMgkkqj5qjCnkuC3BtU+8qHQA=; b=djSHNxU0XvGz9CPQ5FO67or8RFdUz8y8LRPeeHY+nc7p7cw9c0ldCM6dOBwKL8zdrx 8EBZjS0SKhGV5kaatAKNHiKtJD7qcee7FG15HwRAIf/OxvfTmjWX8lvw0mtzE6bV6XoU BLp2veIOcfgrSnSwigNAP6H1mmd20C/swTDkSBJpHoB+vaD2LFO0Xzv9rMEiU8bfPqS8 OH9icR6Mc9pM486ckWiLsEpA/70wWtY5v4OcgnXx6d1VdxW13hKlYibTjKQkfg7RejTo Xduo6qtRBBji7aJjModapsFRdtHrkHffaXOA44bR/mkfFKr5kaStJhiLnmxYq9vd7x5H NYYQ== X-Gm-Message-State: AOAM533Po01dtOjbMUDvC+CH72uTDTIYXg/rTEjMNrTCljYpzHLidtbb 6jZjWhxUlswzC46nJ2qESsrw16k2So8irg9F90g= X-Google-Smtp-Source: ABdhPJzWon6/6sDOxXEY/y951yC+obddnQcuL3nQKRWvvZRdbnEZEQI9Tb+H2qi1ekinxn7kRu0eqL9EprOehvKAgK8= X-Received: by 2002:a05:620a:d56:: with SMTP id o22mr35229172qkl.753.1638829015198; Mon, 06 Dec 2021 14:16:55 -0800 (PST) MIME-Version: 1.0 References: <61ac9759.1c69fb81.b0241.1e6fSMTPIN_ADDED_MISSING@mx.google.com> <268F5B4F-4770-48AA-B212-DE23116BCF4C@gmail.com> In-Reply-To: Date: Tue, 7 Dec 2021 05:16:44 +0700 Message-ID: To: Hassan Ahmed <7snovic@gmail.com> Cc: Claude Pache , Rowan Tommins , php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] RFC [Discussion] array_column results grouping From: the.liquid.metal@gmail.com (Hendra Gunawan) > > Hello Folks, Thanks a lot for your feedback, as already mentioned in > the RFC and as mentioned by Rowan too a new function is an option. I > think that mostly we will go with the new function option. > I will try to edit the PR to add a new function, does there any > suggestions/naming conventions for the new function? a colleague > suggested being `array_group_by` and Hendra already suggested to be > `array_column_group` which is good too. It would be better if You add another voting item for this one. In my opinion, `column` is less important to be included, and `array_group` is sufficiently descriptive. `reducer` is one of the candidates to be included. Additionally, there are `mapper`, `filter`, and `sorter`. So Obviously we need a new function, rather than modify the old one. To be clear and to make it simpler, all callbacks operate on the deepest subgroup. Signature: reducer(array|object $item, int|string $index, mixed $cumulative): mixed mapper(array|object $item): array|object filter(array|object $item, int|string $index): bool sorter(array|object $item1, array|object $item2): int A note in case you are able to implement them: - `reducer` and `mapper` cannot coexist in a single function call. - `filter` should be executed before `reducer` or `mapper`. - `sorter` should be decided whether it executes before or after `reducer`/ `mapper`: `sorter` is more suitable to execute before `filter`, but more suitable after `mapper`. A note for consumers: - `mapper` is designed to operate on the subgroup item, but it can be operated on the field value of the item. - filtering can be done inside `reducer` or `mapper`, but the number of subgroup members is as it is. With dedicated `filter` supplied, we can decrease the number. - If You want to filter an intermediate group, You can use `unset` or `if-else` $group = array_group($people, ["education", "sex"], FN_REDUCER); foreach ($group as &$eduGroup) { foreach ($eduGroup as &$sexGroup) { unset($sexGroup["male"]); } } Not a perfect solution, but at least your code is reduced. Best Regards Hendra Gunawan.