You are here: Re: sorting numbers « PHP Programming Language « IT news, forums, messages
Re: sorting numbers

Posted by Rik on 08/22/06 15:40

Davide wrote:
> Hi all..
>
> I'm trying to sorting a file in a directory.
> It works well but it sorts me the number in this way:
>
> 1
> 10
> 11
> 2
> 20
> 21
> ...
>
> is there a way to sort in this way?
> 1
> 2
> 3
> ..
> 10
> 11
> 12
>
> this is my code:
>
> <?php
> if ($handle = opendir('/home/davide/')) {
> $files = array();
> while (false !== ($file = readdir($handle))) {
> if (($file != "." && $file != "..") AND
> (eregi($select,$file))) $files[] = $file;
> }
> closedir($handle);
> sort($files);

Change to natsort($files);

Grtz,
--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация