May 16, 2016

PHP Function ksort to recursive_ksort

PHP Function ksort to recursive_ksort

function recursive_ksort(&$array)
{
    if (is_array($array)) {
        ksort($array);
        array_walk($array, 'recursive_ksort');
    }
}

An important thing in this function is variable by reference instead of returning value each time. So its easy to understand for those guys who worked in C language and a little difficult for routine PHP coders. Its relatively easy and practical to use a variable by reference instead of managing it by consuming more memory.

Last updated: May 20, 2016