|  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: -
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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
5 + 47 = ?
Subscribe to this entry?

 [2010-06-24 23:19 UTC] dsrthorne at gmail dot com
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;


        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.


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 23:01:26 2019 UTC