php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52177 please implement recursive ksort
Submitted: 2010-06-24 23:19 UTC Modified: -
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: dsrthorne at gmail dot com Assigned:
Status: Open Package: Arrays related
PHP Version: Irrelevant OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dsrthorne at gmail dot com
New email:
PHP Version: OS:

 

 [2010-06-24 23:19 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Oct 19 10:01:26 2019 UTC