Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116535 Return-Path: <7snovic@gmail.com> Delivered-To: mailing list internals@lists.php.net Received: (qmail 33221 invoked from network); 28 Nov 2021 07:19:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Nov 2021 07:19:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 170891801FD for ; Sun, 28 Nov 2021 00:17:02 -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.6 required=5.0 tests=BAYES_50,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: <7snovic@gmail.com> Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (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 ; Sun, 28 Nov 2021 00:17:01 -0800 (PST) Received: by mail-io1-f53.google.com with SMTP id z18so17005201iof.5 for ; Sun, 28 Nov 2021 00:17:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=hpQiWNEH0dUSeOYP5M5gNOBapQonj6s6C9fc2dpl1Zs=; b=eaPXiMJxV8k//5koyFHsaL4+Vg7xA1O5DaKrLkuEfUFw/WEAMVrl1q38bWOtQVOzCT 6f7gEa3++LWrEUGDayBwmuqHmztOmzlXDRTNFKgUOt3UPCdRhTfeNeZ76if0GTX8CBy5 bYiaTBvzln+bQ9MX8P83+ggy0cJllQhIjc1DRXX0tzi8piRCd4t09VFbDBxA7m3SMyt2 5PsndY3O+gCKIC8gJpkE3iU5rNwFnRIONc1YfcFRPjaRkQ27KZI+9iDxbIEHAsdmIyjZ ldsL6V8JL0n3coeR7NJgUPo31Q7/7aspuQrXwK9ELB/USB/FNGP0gZh8vEqRcmUyRmIS m/MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=hpQiWNEH0dUSeOYP5M5gNOBapQonj6s6C9fc2dpl1Zs=; b=S4RzjiqvL9Iqm3qXRCgnmXzeGlC5CFcUShBNQ9ln9/hqFN9fg7XyG/xTxAF48MJ+X0 Wcw1LFmvH77PjDq5h3F2Dejo8/DDY7DghWkn58YsFCaFBMJYWaN4Ovi+WwtRvR6qQHu2 Ix7XPP1iFj8/WEXeIjWB5RqDzwlYq/0exUA+5Mb48eBhpPxLz8L9+dPw6WKfswddTYQo psRAa96KUaA1ftmUdTC+QKFiHuFPZVUbheIvK5/PZ8Qm9IPIOHgZuAeReq33UnSpGKG2 70cw37HuAPrxUUKYkIO+2Gb9OSBL9RMjK64VKFqa1K2RGvO48zO5Szjh+f328NQn0O/D EOzA== X-Gm-Message-State: AOAM533pquclRPdOBQP73zR2WN9ig/e4A2YXsVi/SsNoB9x1iOFOs+sh XsPqw3H4y4JivkmOa3+YGTfTl2/YCWwnXplKjHdTItwjyW4= X-Google-Smtp-Source: ABdhPJxOi3b1FKVtB0joUYFikCYnk7zFTd3/pNKeAcO/wyYRA+KO9jeED67KFhyhKSqLAfqId89N8UEk7+JR9tN0g0M= X-Received: by 2002:a02:ab8f:: with SMTP id t15mr61327376jan.147.1638087421114; Sun, 28 Nov 2021 00:17:01 -0800 (PST) MIME-Version: 1.0 Date: Sun, 28 Nov 2021 10:16:50 +0200 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Subject: Grouping array_column results From: 7snovic@gmail.com (Hassan Ahmed) 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. ``` 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