Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116097 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70949 invoked from network); 19 Sep 2021 12:31:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Sep 2021 12:31:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9852C1804C0 for ; Sun, 19 Sep 2021 06:11:49 -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=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_HOTMAIL_RCVD2, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8075 40.80.0.0/12 X-Spam-Virus: No X-Envelope-From: Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11olkn2018.outbound.protection.outlook.com [40.92.20.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 19 Sep 2021 06:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MfWcsAhIrDHYwTkXh2rGoO5iv4tW+cq03LDvstO+nkcP6yyumu6PUb485XSqF8VsZ7kH4SHnobmbImWVGppNEeLw1qKc/h8JyIo1gT5dcfMKbi2/ym74rg9qK6H4Z/NXSw0RveNL8kgFm6KIJF7Kvab5BtpcbV+gpDsRfSNIAQBRNp+8iWQO2+OKKOCvklFZmY5nTTBzvoDDkOI8ikGv0rfkKD4rjn+KosLaeD0tzvc6ftjMbKGJCrVh21NVwbA/K235l6ZQm/ecXA8m1sVEVuAsZG5SS5VJh/S6TRcgqMy65IhC8RgnMVkZKEQ6pK3RSy+avYov7FyH3G6ZDOSPIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=SeKFovQHWizNb2E3kVBoNxaP8JPWa6urr+WRkD5KPV4=; b=nBmP1Wq+w5eq9O/Otvjd8/cXwEFxqldSbaogz9xtyg7XZW8jJ2VnBnHPO0C/FzBZtzu5DiLNEqovukgABcoBPYoG/Bl4AyLKsfBSMBL0JollMb19/idLnw4s2iInoUKhf8NbiMIJKXSvaUkdAnqhqNi1clmEXOW/BzCE/wZhTKaHhIPu6SDil9XBdeMIUfaYEUzGIW+S2OL+EoY2LT15HAh7Ql9FloxYIR8FGVuO+KYd4MXUf/7LFWcJ8nuQ0ZJiVWWERhxxi2LWIst+KZSPC1vGMMKBe4n8gWWQdcffbChg5YDAzQuy5VLma+xugnUz4fwxfp2Xn5HQrTmC9JnFvg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SeKFovQHWizNb2E3kVBoNxaP8JPWa6urr+WRkD5KPV4=; b=e7ZQUzK9xBmu2xbdepmThfvnZVEwbAENLjlDJug4dwtT7Ql8hkUCTB9OveHsHYbvEnlab3GxgvuGX2LKR6oupEfHIdJBB47NIHrVO8p0ic5tAQfirxf27rVDIVjiU3OE8nGbHEgAZA3zyzLyduXaes3tZ/g3q4vj5mT8wlqADObAAWMaeQMN/Y6k3AIpmp0I8CcnozsGTzYj+R0zDRFAmdyokMdGwQp1PckuRGERi7nRC1dSwh7PdMxDREvbgEgyfduaoUvU3eLMuoDPgLpbygIjJEwXjs8r50XwWmot+2Eu3kHjJzcVfpbumo3gBXBZbS0kWeN7fhW1iv+Aoyj9Lg== Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2603:10b6:5:1cf::26) by DM6PR07MB4587.namprd07.prod.outlook.com (2603:10b6:5:97::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Sun, 19 Sep 2021 13:11:47 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::7181:60db:c4d2:835]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::7181:60db:c4d2:835%7]) with mapi id 15.20.4523.018; Sun, 19 Sep 2021 13:11:47 +0000 To: "internals@lists.php.net" Thread-Topic: Proposal: Adding an ARRAY_FILTER_REINDEX flag to array_values Thread-Index: AQHXrVaY5NYiU2cHn0abe/KgvhewOg== Date: Sun, 19 Sep 2021 13:11:47 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: 52c36232-1dea-9563-0fb6-ba0d73fc66d9 x-tmn: [BTKk3RcIGw80k7xXHUxq9Un+hZazaPOEdk5PvEG1dY8j7HU6dWqGarLLTO5wt5KQ/AY08BcADqw=] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8b625c8b-8237-4857-8503-08d97b6f096c x-ms-traffictypediagnostic: DM6PR07MB4587: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 4LJpalLTVB+xPBMf5QgO3ZNJ4rPcVBq0PvK9BkHheqcVe8RHGZKsOdrnyUUokFkeVpnU6Prkp9uMjWX/dpfdYjfsBti8+YVNhVEuKv9sMQSn3k+v7lWGyNyWRTQaZQde97bxT0YZDVix72fV8aynBmNiiD19+DFetoS+pqUyMTZ2LStKcsDISfpbtwsvSRhfLe16T079GO9cIhWDnflCb+4FkWsGuVf92lXMQqc3tkFcC3GiLCF1uf29cvuoAFfDO7sRj+dAv4atRwA5u1Wds2A4lJKN/bMmqD4br5m3NpwyCZLCyQtXW08dDScUBtVt8EHuOP7hfDvVvbHGdGzyRogS4u++T5BoWgWBHnnr2PcVCDwLQHM8A7xzdkkkYuPyYhLROdAk4Q9G829FRKwSF7KAdQHZvFijD+05RZlfqfBvtHe6SZypmfKuVGmFXdpVVtaRK00i9TEEAVGQt3Nz0Wg37oeyoNgcz9YfS003CQk= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: QhHP41YEMb+va4dRUBsowmbfsGtRWFc1rSVWC0o9nADBvQiI6g3Fb32EWgx3IQ9smsxxipBDmGConBKKIT1GFoZ4wCxCm7LRersFnqHM34/ItCEuIJCd8k7poBa4+USm34RivTLSi2rWTNJhIZh2r1W11uwhtTebCi2iJ7V/SIyeTJgPuyf1d+TZ0gVXNKAkmvaW5azp64+tHjCNZ9MwIA== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-3174-20-msonline-outlook-35401.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR07MB6618.namprd07.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 8b625c8b-8237-4857-8503-08d97b6f096c X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Sep 2021 13:11:47.8869 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR07MB4587 Subject: Proposal: Adding an ARRAY_FILTER_REINDEX flag to array_values From: tysonandre775@hotmail.com (tyson andre) Hi internals,=0A= =0A= Currently, array_filter will always return the original keys.=0A= This often requires an additional wrapping call of array_values(array_filte= r(...)) to reindex the keys and return a list.=0A= (or applications may not realize there will be gaps in the keys until it ca= uses a bug or unexpected JSON encoding, etc.)=0A= =0A= PHP is also more memory/time efficient at creating packed arrays than it is= at creating associative arrays.=0A= =0A= What are your thoughts on adding `ARRAY_FILTER_REINDEX`, to ignore the orig= inal int/string keys and replace them with `0, 1, 2, ...`=0A= =0A= ```=0A= php > echo json_encode(array_filter([5,6,7,8], fn($value) =3D> $value % 2 >= 0));=0A= {"0":5,"2":7}=0A= // proposed flag=0A= php > echo json_encode(array_filter([5,6,7,8], fn($value) =3D> $value % 2 >= 0, ARRAY_FILTER_REINDEX));=0A= [5,7]=0A= ```=0A= =0A= https://www.php.net/array_filter already has the `int $mode =3D 0` which ac= cepts the bit flags `ARRAY_FILTER_USE_KEY` and `ARRAY_FILTER_USE_BOTH`=0A= These could be then be combined with the proposed bit flag `ARRAY_FILTER_RE= INDEX`, e.g. to filter an array based on both the array keys and values, an= d return a list without gaps.=0A= (and if $callback is null, this would return a list containing only the tru= thy values)=0A= =0A= Thoughts? =0A= =0A= Thanks,=0A= Tyson=