Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120485 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 31351 invoked from network); 31 May 2023 08:49:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 May 2023 08:49:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BBA0B180505 for ; Wed, 31 May 2023 01:49:43 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,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, T_SCC_BODY_TEXT_LINE 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-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 31 May 2023 01:49:43 -0700 (PDT) Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-75b064451d3so337471485a.0 for ; Wed, 31 May 2023 01:49:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685522982; x=1688114982; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=lDS5tT7rm9WzcMSz6bpJudDe1NMPf/KP45H/Qr/3YZY=; b=S8cO4KUl03NOo7NbSH3nKB2yFElsV/3+H///WuLzil7t5Qum1xF+WTy2RFz9wNYNPA Y6foG/vTA4xYcsVgujhTH0fQhYDlM+VIVd/BRMHXH5ijYfJn5DQdEztcxylzjMgMKL5s FBO8sBxCBH/T2Pf49wLpIQrHELe5TPcJYMeqimxVRtnQ2lIPe8qb8eHZ1Q75lWVbaTZ4 PLI+u9mMfvnU56XZGAS3w5ALsScirWttnuZ0Jpr37fvpVg+3TQkRaj119IeeOU1HNVPc S+jMsZ+MdinlrWcNd2PaZltedV0j6hFipxkxZD9fUe5vCTE861HZljh4tyhw0BRbjIAm xAng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685522982; x=1688114982; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lDS5tT7rm9WzcMSz6bpJudDe1NMPf/KP45H/Qr/3YZY=; b=faKZVgPjgKQHsq7Nmt2dMwSodSkY1cWn9X0f32E5CQnubBXXihxekb/3h2aogJBKBK JRoaoPfY8qEiaJ7IIpqFPhZsvNSfV1lT/+TvIKC4bNHWXAXWtXZ3VZSA+Ql0oACDjvo4 XOtVjtVk3uHRn6apLHtbmraGxvYoDWxqAXGUpr0b96nkL0YjaQCFislqW/QXGdlRwno3 2pXZ3KDa0lLI6RUkb4RAuzQqK/8nj/smjPJ3AVmX9c01MqC/VhAMFRlukJ4J84Pv4z2B qD+DWzloYS3NEEtvxjmPDaUo1svOZPqCT62dpz2rL0dyUH/ColL7CLKYJcCSWA60npBf DhMA== X-Gm-Message-State: AC+VfDxsych5B52FAuLVCVDfbciESLqoUfxV1BI5BdgruY731lbJk3MH 3/p3ObcuaB7viS27N23LUPE1J2uK6rBLWl/gjcJl1Usy0777tA== X-Google-Smtp-Source: ACHHUZ5MddiHiDGSvNUX4F/QOqvo7OoyXRZrSGmwvzzAN2xjO6fIX7yw7rWAKcN+HTmbEnwxsGwzu6bgq5gW7L6klxA= X-Received: by 2002:a05:620a:27c9:b0:75b:23a1:830b with SMTP id i9-20020a05620a27c900b0075b23a1830bmr5069649qkp.6.1685522982399; Wed, 31 May 2023 01:49:42 -0700 (PDT) MIME-Version: 1.0 References: <289E585B-EF8B-4B17-89BE-BE8295FD9FE1@gmail.com> <12bede25-36ad-037d-8802-6348da7a2e3d@alec.pl> In-Reply-To: <12bede25-36ad-037d-8802-6348da7a2e3d@alec.pl> Date: Wed, 31 May 2023 11:49:27 +0300 Message-ID: To: Aleksander Machniak Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] [Discussion] Add new function `array_group` From: rokas.sleinius@gmail.com (=?UTF-8?Q?Rokas_=C5=A0leinius?=) On Wed, 31 May 2023 at 10:30, Aleksander Machniak wrote: > > On 30.05.2023 13:34, Boro Sitnikovski wrote: > > I propose introducing a function to PHP core named `array_group`. This > > function takes an array and a function and returns an array that > > contains arrays - groups of consecutive elements. This is very similar > > to Haskell's `groupBy` function > > . > > > Sorry, I'm sick right now and have no clue, but how does it relate to > https://wiki.php.net/rfc/array_column_results_grouping > > -- > Aleksander Machniak > Kolab Groupware Developer [https://kolab.org] > Roundcube Webmail Developer [https://roundcube.net] > ---------------------------------------------------- > PGP: 19359DC1 # Blog: https://kolabian.wordpress.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > Okay, I will just share my decade-plus-old take on this problem for anyone interested. I find defining the desired array grouping rules is self-explanatory - and can get arbitrarily complex when required - in this format: `columnA=>*`. The format can get as complex as `columnA[columnB][]=>columnC,columnA` - and more - and I bet you can decipher what you get from that without much difficulty nor documentation. It's also quite simple to compose your own. Here's the whole source code for the PHP function along with test coverage: https://github.com/laravel/framework/discussions/45638 Cheers