Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108856 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 29388 invoked from network); 4 Mar 2020 22:05:54 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 4 Mar 2020 22:05:54 -0000 To: internals@lists.php.net References: <9a590afe-8674-4d5c-b18f-2bc15786348c@www.fastmail.com> Date: Wed, 4 Mar 2020 21:25:24 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.2 MIME-Version: 1.0 In-Reply-To: <9a590afe-8674-4d5c-b18f-2bc15786348c@www.fastmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 46.59.72.204 Subject: Re: [PHP-DEV] Make sorting stable From: ajf@ajf.me (Andrea Faulds) Message-ID: Hi, Larry Garfield wrote: > If I'm understanding the definition of stable here, it means that if two values evaluate to equal they will always end up in the same order in the output that they were in the input, yes? So (trivial example): > > $a = ["3", 2, 3, 5]; > > Sorts to: > > [2, "3", 3, 5]; > > always, whereas right now it may sort to that or to [2, 3, "3", 5], somewhat randomly. Am I understanding correctly? (That is _my_ understanding, though I'd take Nikita's word for it rather than mine.) I think you indirectly point out a good reason to have a stable sorting algorithm for PHP: PHP's weird type-juggling equality rules mean several kinds of values that are not really (===) equal will compare equal (==) so far as sorting cares, which probably means messy results sometimes when paired with an unstable sort? Thanks, Andrea