Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128955 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 lists.php.net (Postfix) with ESMTPS id 429E01A00BC for ; Fri, 24 Oct 2025 22:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761344144; bh=sUjtkDOtY2QOGVq2H1yi2Cppbuzq6RjZRi7SXzjdKVI=; h=Date:Subject:To:References:From:In-Reply-To:From; b=hBhWvVcZiVYfUmCHMy0DMqXMNuf5GsgWWqPAlOwCPUik7FX5wohL5oYmdRNxPeXSm J3upNDKUkYvJrsZyNw52KVSWsxTnDawdf4IjSmcEF9L4So3+7XqT9iYjNRi96ahX0K 2q0n5PEp9vfcqXLMm6Pw35codvVmqy/aqW5OEOvISPKDZQsPqDL42KGlCz2nIcKCfq QcVHVq82OW42X5/3CAjGODljBKpPFjktJy8XZh/RteHwDf1ulGNxdiednZxLFSwkm7 TKNtpaVbdZeYn55nRKptJwrt2IOW4RKyih3PHRfPt/c/jchbHbFLiyKdfOZ3irqK5H +ViAnm/9l7l5g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 04C2C1801D8 for ; Fri, 24 Oct 2025 22:15:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DMARC_MISSING, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from emily.smtp.mailx.hosts.net.nz (emily.smtp.mailx.hosts.net.nz [43.245.52.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 24 Oct 2025 22:15:43 +0000 (UTC) Received: from 122-57-27-239-adsl.sparkbb.co.nz ([122.57.27.239] helo=[192.168.1.67]) by emily.smtp.mailx.hosts.net.nz with esmtpsa authed as varteg.nz (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim 4.96) (envelope-from ) id 1vCQ4L-0026gq-37 for internals@lists.php.net; Sat, 25 Oct 2025 11:15:34 +1300 Message-ID: <4b605609-47c2-4df5-be71-8b962ad9ff1e@varteg.nz> Date: Sat, 25 Oct 2025 11:15:28 +1300 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] RFC proposal for adding SORT_STRICT flag to array_unique() To: internals@lists.php.net References: Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Hosts-DKIM-Check: none From: Weedpacket@varteg.nz (Morgan) On 2025-10-25 08:34, Jason Marble wrote: > Hello everybody! > > > The potential for a `SORT_NATURAL` flag also came to mind as another > useful addition, but I believe `SORT_STRICT` is the more critical > feature to discuss first. > I know I find array_unique generally useless due to its insistence on stringifying everything for comparison. ``` $uniques = []; foreach($source_array as $a) { if(!in_array($a, $uniques, true)) { $uniques[] = $a; } } ``` I seem to recall part of the issue is that array_unique works by sorting its elements so that "equal" values are adjacent. I know this would be done on O(n log(n)) vs. O(n^2) grounds, but that could be addressed at least in part by a smarter sort criterion that sorts by type/class (in some arbitrary order) before sorting by value. For uncomparable types (i.e., instances of most classes) this would be by object ID, because we don't _actually_ care about ordering.