bsnmcahi Posted October 25, 2012 Share Posted October 25, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/269876-sorting-a-numeric-array/ Share on other sites More sharing options...
bsnmcahi Posted October 25, 2012 Author Share Posted October 25, 2012 Found the answer! been working on this all night! post a message for help and 5 mins later find answer! // $files is your array usort($files, "strnatcmp"); this sorts filenames 1,2, 3,4 etcc instead of 1,10,100 etc.. Quote Link to comment https://forums.phpfreaks.com/topic/269876-sorting-a-numeric-array/#findComment-1387582 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.