|  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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 18 18:03:39 2021 UTC