Req #52177 [Opn->Wfx]: please implement recursive ksort

From: Date: Wed, 01 Dec 2021 15:56:42 +0000
Subject: Req #52177 [Opn->Wfx]: please implement recursive ksort
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238094@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=52177&edit=1 ID: 52177 Updated by: cmb@php.net Reported by: dsrthorne at gmail dot com Summary: please implement recursive ksort -Status: Open +Status: Wont fix Type: Feature/Change Request Package: Arrays related Operating System: linux PHP Version: Irrelevant -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: I'm having a hard time to understand why we should introduce a recursive ksort(), but not at the same time recursive variants of the other sorting functions. Then again, that would be a dozen new functions which are likely not too often needed. Your userland implementation looks fine, so where is the point in adding that to ext/standard (besides that a C implementation *might* be more performant, what would need to be measured, though)? I'm closing this as WONTFIX. If anybody is still interested in this, please pursue the RFC process[1]. [1] <https://wiki.php.net/rfc/howto> Previous Comments: ------------------------------------------------------------------------ [2010-06-24 23:19:45] dsrthorne at gmail dot com Description: ------------ I've a problem wherein I'm using SimpleTest's testIdentical to compare nested arrays, and if the key order differs it throws an error. What I really care about is making sure the same content exists in both, order independent. My solution was to implement a recursive ksort to run the nested arrays through to guarantee key order was the same, regardless of how the arrays are given to me initially. It seems like it would be useful to have this functionality in base php. Test script: --------------- My short php-based implementation looks like this: function rksort($array = null) { if (!@is_array($array)) return $array; ksort($array); foreach ($array as $index => $notused) { $array[$index] = rksort($array[$index]); } return $array; } Expected result: ---------------- Results confirm expectations: the data structure is key sorted recursively using ksort. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=52177&edit=1

« previous php.bugs (#238094) next »