Re: [RFC] Change behaviour of array sort functions to return a copy of the sorted array

From: Date: Mon, 21 Oct 2024 11:17:07 +0000
Subject: Re: [RFC] Change behaviour of array sort functions to return a copy of the sorted array
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-125822@lists.php.net to get a copy of this message
On Mon, 21 Oct 2024, 18:09 Morgan, <weedpacket@varteg.nz> wrote: > You can’t use: > $sorted_datasets = array_map(sort(...), $datasets); > You want > $sorted_datasets = $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 >

« previous php.internals (#125822) next »