1
在我的php项目中,我有一个名为Gallery1的文件夹(路径是images/gallery1)。其中包含名为1.jpg,2.jpg,20.jpg,8.jpg等的图像。我想按照升序显示该文件夹中的所有图像(1.jpg,2.jpg,8. jpg,20.jpg等等)。有人知道吗?以特定顺序显示文件夹中的图像
在此先感谢
在我的php项目中,我有一个名为Gallery1的文件夹(路径是images/gallery1)。其中包含名为1.jpg,2.jpg,20.jpg,8.jpg等的图像。我想按照升序显示该文件夹中的所有图像(1.jpg,2.jpg,8. jpg,20.jpg等等)。有人知道吗?以特定顺序显示文件夹中的图像
在此先感谢
<?php
// Find all files in that folder
$files = glob('images/gallery1/*');
// Do a natural case insensitive sort, usually 1.jpg and 10.jpg would come next to each other with a regular sort
natcasesort($files);
// Display images
foreach($files as $file) {
echo '<img src="' . $file . '" />';
}
// ???
// Profit :D
?>
你可以使用natsort这种种的自然顺序。从PHP.net
$array1 = array("img12.png", "img10.png", "img2.png", "img1.png");
natsort($array1);
Array
(
[3] => img1.png
[2] => img2.png
[1] => img10.png
[0] => img12.png
)
例如,这可以帮助你[排序](http://stackoverflow.com/questions/260387/ordering-a-list-of-files-in-一个文件夹,使用的PHP) – Dotnet 2011-03-29 11:00:37