Jump to content

Sorting A Numeric Array


bsnmcahi

Recommended Posts

Hi I want to show all images in a folder. My images are named 1.svg, 2.svg, 3.svg, 4.svg, 5.svg, 6.svg, 7.svg, 8.svg, 9.svg, 10.svg, 11.svg, 12.svg, 13.svg, 14.svg, 15.svg, 16.svg, 17.svg, 18.svg, 19.svg, 20.svg.

 

 

 

When I sort with natural sort function or any sort function I can find it does not do it correctly.

 

it goes 1, 10, 100...

 

I need it be normal order of filenames..

 

here is the page and how it loading the results now:

 

http://www.wallartstickersuk.com/imageviewer.php

 

Martin

 

 

 

 

$files = glob("img/products/database small image/*.*");

 

 

 

sort($files,SORT_NUMERIC);

 

for ($i=0; $i<count($files); $i++)

{

$num = $files[$i];

print $num."<br />";

echo '<img src="'.$num.'" width="250" alt="random image" />'."<br /><br />";

}

 

 

Thanks

 

Martin

Link to comment
https://forums.phpfreaks.com/topic/269876-sorting-a-numeric-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.