Re: sorting an array..dont know numeric or alpha-numeric
| From: | Kevin Waterson | Date: | Sat, 07 Aug 2004 03:19:41 +0000 |
| Subject: | Re: sorting an array..dont know numeric or alpha-numeric | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-193076@lists.php.net to get a copy of this message | ||
This one time, at band camp, PHP Gen <genphp@yahoo.com> wrote:
> Hi,
> I have a function that reads jpg files (thumbnails)
> from a directory and puts all the files names into an
> array...I want to sort that array by the filename,
> problem is, I dont know if filenames will be pure
> numeric (eg 001.jpg,002.jpg) or alpha-numeric
> (asdf001,asdf002)
<?php
$hdl = opendir('./');
while ($dirEntry = readdir($hdl)) {
if (substr($dirEntry, 0, 1) != '.') {
$listing[] = $dirEntry;
}
}
natsort($listing);
closedir($hdl);
foreach($listing as $blah) { echo $blah.'<br />'; }
?>
or something.
Kevin
--
______
(_____ \
_____) ) ____ ____ ____ ____
| ____/ / _ ) / _ | / ___) / _ )
| | ( (/ / ( ( | |( (___ ( (/ /
|_| \____) \_||_| \____) \____)
Kevin Waterson
Port Macquarie, Australia