Hi,

I'm trying sort an array. It has entries like this:

file_1.ext
file_2.ext
file_3.ext
file_10.ext
file_40.ext

and so on.

I want to sort them alphabetically first and then by the numbers.
If I sort them normally I get them like this:

file_1.ext
file_10.ext
file_2.ext
file_3.ext
file_40.ext

What I'm thinking of is like this:

function mycmp($a, $b) {
        if ($a == $b) {
                return 0;
        }
        $a_n = preg_match("/\D+(\d+)\D+/", $a, $a_out);
        $b_n = preg_match("/\D+(\d+)\D+/", $b, $b_out);


return ($a_n[1] < $b_n[1]) ? -1 : 1; }

But it doesn't work the way it should. Any suggestions?
So this is a the callback-function for the usort funtion.

Shmuel.

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



Reply via email to