On Tue, Sep 4, 2012 at 7:23 PM, John Taylor-Johnston
<jt.johns...@usherbrooke.ca> wrote:
> The problem is I'm sorting the key. The alphabetical thing is in the key.
>
> David OBrien wrote:
>>

Taken from the natsort manual page comments:

<?php
/**
 * keyNatSort does a natural sort via key on the supplied array.
 *
 * @param   $array      The array to natural sort via key.
 * @param   $saveMemory If true will delete values from the original
array as it builds the sorted array.
 * @return  Sorted array on success. Boolean false if sort failed or
null if the object was not an array.
 */
function keyNatSort($array, $saveMemory=false)
{
    if(is_array($array))
    {
        $keys = array_keys($array);
        if(natsort($keys))
        {
            $result = array();
            foreach($keys as $key)
            {
                $result[$key] = $array[$key];
                if($saveMemory)
                    unset($array[$key]);
            }

        }
        else
            $result = false;
    }
    else
        $result = null;

    return $result;
}
?>

- Matijn

PS. Please bottom post on this and probably any mailing list

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to