* Thus wrote Shmuel ([EMAIL PROTECTED]): > file_1.ext > file_2.ext > file_3.ext > file_10.ext > file_40.ext > > 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;
you need to use the $x_out variables: return ($a_out[1] < $b_out[1]) ? -1 : 1; if all the names are prefixed with 'file_' it might be a bit more efficiant if you do something other than preg_match(): $a_n = (int) substr($a, 5); // (int) forces 10.ext -> 10 $b_n = (int) substr($b, 5); return ($a_n < $b_n) ? -1 : 1; Curt -- "My PHP key is worn out" PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php