|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-12-01 15:56 UTC] cmb@php.net
-Status: Open
+Status: Wont fix
-Assigned To:
+Assigned To: cmb
[2021-12-01 15:56 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 10:00:01 2025 UTC |
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.