Re: usort
| From: | David Otton | Date: | Sat, 25 Oct 2003 01:57:02 +0000 |
| Subject: | Re: usort | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-167513@lists.php.net to get a copy of this message | ||
On Sat, 25 Oct 2003 04:03:12 +0300, you wrote:
>I don't know what the names are. I just know that there might be numbers. :)
>
>It still doesn't work. It gives very odd results with the $x_out variables.
<?php
function cmp ($a, $b)
{
if ($a == $b)
{
return (0);
}
$a = explode ('_', $a);
$b = explode ('_', $b);
if ($a[0] == $b[0])
{
return (((int)$a[1] < (int)$b[1]) ? -1 : 1);
}
return (($a[0] < $b[0]) ? -1 : 1);
}
$a = array('file_3.ext', 'file_10.ext', 'xxx.ext',
'file_2.ext',
'file_1.ext');
usort ($a, 'cmp');
print_r ($a);
?>