Re: array_multisort into Natural order?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 14 December 2010 10:50, Richard Quadling <rquadling@xxxxxxxxx> wrote:
> On 13 December 2010 19:59, George Langley <george.langley@xxxxxxx> wrote:
>> Hi all. Can use natsort($array1) to sort a single array of filenames into a "natural "alphanumeric order - 1.php, 2.php, 5.php, 10.php, 20.php, etc.
>> But usingÂarray_multisort($array1, $array2, $array3) doesn't offer a natsort option, so I end up withÂ1.php, 10.php,Â2.php, 20.php,Â5.php,Âetc.
>>
>> Anyone have a solution to this limitation already? Nothing found in the archives or Googling.
>> Â Â Â ÂThanks.
>>
>>
>> George Langley ÂÂ Multimedia Developer ÂÂ Audio/Video Editor ÂÂ Musician, Arranger, Composer www.georgelangley.ca
>>
>>
>>
>
> Based upon code I found at [1] I have the following function [2] which
> I use to sort result sets. I've just added natural sorting (and
> natural caseless sorting) and some examples on usage.
>
> It might be slightly over the top, but it works well for me. No need
> to extract the columns from the rows to supply to the sorter.
>
> If you like it and find any issues with it, or enhancements, then I'd
> be grateful if you could pass them back to me.
>
> Richard.
>
>
> [1] http://www.php.net/manual/en/function.array-multisort.php#68452
> [2] http://pastebin.com/8JsMX7yS

The function uses a closure for the sorting. If you are on PHP <
5.3.0, then you'll have to extract the function into a normal one and
add ...

global $a_AMCOrdering;

to each function.



-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux