On 2024-10-22 00:17, mickmackusa wrote:
On Mon, 21 Oct 2024, 18:09 Morgan, <weedpac...@varteg.nz
<mailto:weedpac...@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 <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 <https://3v4l.org/FeIpj> -- notice how rows with
keys 2, 5, and 10 are sorted as strings.
Mick
Right, but the issue was that array_walk() is the only
callback-parameterised array_* function which is even _compatible_ with
sort(). As you point out, even then it's problematic.