Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125822 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id AE59D1A00BD for ; Mon, 21 Oct 2024 11:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1729509585; bh=j5PEVP/syi5rx3uq9ytFtaUBLtUbw8n7BsDrtDN4CoQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=NAMc4tUFR1RyEW+HXMexGsZwx0Pg1bbyU9jPNh51W1m4/Lj+wC5N6foMRhVzbUx4a XGVnoZWMbDXmeR4DzfLWYtS1WoT8W2XAIaKAkwUFPUXL7BoOFHRe/+TO6fieferX85 9QvzDHo5rMNXaN2NCy9LoXBfoT70Cm5+hMfgbzInCa+rYOluPcXlPgQRVjrCRRH2ct OGo0T7DMUmtj22Hfawv3ozhYatuZ0FHPI7SB/0JJQ9hP8kvW2SeIU6GZZJGjaiflHq cpUEHo5Y2oJpjDWS0QMC0m5YDxjqj41IAycSypIAek/dRrQTXN6mfPdSPp5Kg5R43k D9GQRDn1P7H9w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8172918007E for ; Mon, 21 Oct 2024 11:19:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-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,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 21 Oct 2024 11:19:44 +0000 (UTC) Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5c937b5169cso6807945a12.1 for ; Mon, 21 Oct 2024 04:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729509439; x=1730114239; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Epc/DiGKCQUbpOC/GyCCs0hXEZxh0AcMXSYBY/gF6IA=; b=auzB01bLhVtEMI9xVTWQlJtD/aDRwYZlnRBLY0teNfarRLhBN+ZiLQac7vGB34Lsjt XNLcmuqWwKvBPRyrbppesxJ6Amwq416sD0I9gRDYHXSWgcQCrrD4hjrH1+zDCenlmJm9 cnKUkhbHcuL1Y2XBq1N7oTgvmYC5JrUGJy/8MaFHt5bZ+mGX9o/pVlqmcjPANv4Kqn50 yBrxkhlrstvPiKqmMvi4lV2HdVx0x2lsvHIJIdAZ1O34xodJNL301jyMM8hSsff67GFo mdhAAkI5umAsM1TFAKmDdj5LQLT8Qvv4ZZWRxH92g9uXgqZKC0UwkGcXvvvGlrOCVNUT KSxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729509439; x=1730114239; 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=Epc/DiGKCQUbpOC/GyCCs0hXEZxh0AcMXSYBY/gF6IA=; b=kZqeb2wLl28JAd8EdWa4Z3kDaYakg7UnAf+iuZK7aLiyuFepaPFGiDMJbw6Ei6DXZ9 KTwvdUXuK2k1ZhXNqip7rAFeuCmOrfZuxtMabZR+e6T9z+xayDn9Era4WPKtr+IjBT5D l/c1umPMBLASE5cO3041EX7VZQEo5MabgSal8MR8loKUf85rzs9KZybieoA3VZUpzYA7 FtTPraCeq7/PnqYLD7ZqMESBZYidwx8KPXJrPKdmIbK2AkT+qdRsO2oj4q0uWiba4AHB EbEGAow64TnyeWAEb0wg1yAHRrhby7Czy0dk2nf7B0lUbk41Wy6KDR835GxawfcqQC5Z pvnQ== X-Gm-Message-State: AOJu0YxzDPArXMqVa82mDnK/55vGgGEv+28E8+5/NjypMFI+aaI6Qzld nasVyATkoqKWiZ6CzpHRMgv+GRLXlBZu+jxp82HMrDsUJcLguLSe2emnRdwymT/NZrwJBj+Ew9Z izxz2wvyUf7QtrhP1oTzz4m+PTy7CiA== X-Google-Smtp-Source: AGHT+IEUNv52FzFLa6BCHKeqbSF1O1cT8BRFsNSLnGMeliHddBBP3Fw7SOC9aFjGWLqXCunv0vBJlnzwpE3PFK3wwGU= X-Received: by 2002:a05:6402:520a:b0:5cb:7318:15ef with SMTP id 4fb4d7f45d1cf-5cb73181683mr2290937a12.10.1729509438858; Mon, 21 Oct 2024 04:17:18 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <19897c07-ebc8-49e8-9825-30a3fcc00a3e@varteg.nz> In-Reply-To: <19897c07-ebc8-49e8-9825-30a3fcc00a3e@varteg.nz> Date: Mon, 21 Oct 2024 21:17:07 +1000 Message-ID: Subject: Re: [PHP-DEV] [RFC] Change behaviour of array sort functions to return a copy of the sorted array To: Morgan Cc: internals Content-Type: multipart/alternative; boundary="000000000000bd34860624facb78" From: mickmackusa@gmail.com (mickmackusa) --000000000000bd34860624facb78 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 21 Oct 2024, 18:09 Morgan, wrote: > You can=E2=80=99t use: > $sorted_datasets =3D array_map(sort(...), $datasets); > You want > $sorted_datasets =3D $datasets; > array_walk($sorted_datasets, sort(...)); > A warning: no one should ever use array_walk($sorted_datasets, sort(...)); as general-use script. When sorting a 2d array in this fashion (only non-fatally executed with numeric first level keys https://3v4l.org/HaU42), the first level keys will be used as the sorting flag while sorting each row. This means that different rows may have different sorting flags applied -- effectively corrupting the result. https://3v4l.org/FeIpj -- notice how rows with keys 2, 5, and 10 are sorted as strings. Mick > --000000000000bd34860624facb78 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


When sor= ting a 2d array in this fashion (only non-fatally executed with numeric fir= st level keys https://3v4l.org/HaU42= ), the first level keys will be used as the sorting flag while sorting each= row.=C2=A0 This means that different rows may have different sorting flags= applied -- effectively corrupting the result.=C2=A0 https://3v4l.org/FeIpj -- notice how rows with keys 2, 5, = and 10 are sorted as strings.

Mick
--000000000000bd34860624facb78--