pooker Posted July 12, 2008 Share Posted July 12, 2008 I use an array to store multiple image files. I want to sort them according to there numeric value some are named like this series001.jpg series002.jpg The sort function does not work though if I type sort($img); ///the array name is $img It does not sort them and does not even return a value, this same technique works with sorting folders of the same name but not of images it appears. Link to comment https://forums.phpfreaks.com/topic/114397-sort-images-in-php-with-array/ Share on other sites More sharing options...
Xurion Posted July 12, 2008 Share Posted July 12, 2008 sort($array); And rsort($array); Are both correct syntax. Something else must be wrong. Link to comment https://forums.phpfreaks.com/topic/114397-sort-images-in-php-with-array/#findComment-588270 Share on other sites More sharing options...
vikramjeet.singla Posted July 12, 2008 Share Posted July 12, 2008 hi.... i have used following code: $img = array("series222.jpg", "series002.jpg", "series012.jpg" , "series001.jpg", "series003.jpg", "series102.jpg", ); sort($img); print "<pre>"; print_r($img); and it is sorting perfectly Array ( [0] => series001.jpg [1] => series002.jpg [2] => series003.jpg [3] => series012.jpg [4] => series102.jpg [5] => series222.jpg ) Link to comment https://forums.phpfreaks.com/topic/114397-sort-images-in-php-with-array/#findComment-588271 Share on other sites More sharing options...
pooker Posted July 12, 2008 Author Share Posted July 12, 2008 echo "<img src=\"./mangareader/$series/$chapter1/$img[$number]\" >"; There is my code for calling the image when I just leave it lik that, without sort($img); it works perfectly fine, except for being out of order. The minute I put the above code in it acts like nothing is even there, you can click on view image sourc and it acts like it never read the array. Link to comment https://forums.phpfreaks.com/topic/114397-sort-images-in-php-with-array/#findComment-588275 Share on other sites More sharing options...
vikramjeet.singla Posted July 12, 2008 Share Posted July 12, 2008 are you getting these numbers from database???? Link to comment https://forums.phpfreaks.com/topic/114397-sort-images-in-php-with-array/#findComment-588278 Share on other sites More sharing options...
pooker Posted July 12, 2008 Author Share Posted July 12, 2008 no from count function and readdir. The $img array runs a loop and stores each name from the readdir which works perfectly. Then it uses a count function and get action to tell you what page number you are on and stores that in $number, which works perfectly. It always shows up the correct amount of images and everything except for them being out of order, then when I try to sort them nothing happens. It treats it like its not an array or something, but I did this same thing just with folders and it worked perfect on my other script. Link to comment https://forums.phpfreaks.com/topic/114397-sort-images-in-php-with-array/#findComment-588280 Share on other sites More sharing options...
Xurion Posted July 12, 2008 Share Posted July 12, 2008 Can you post all your code? It's difficult to guess the error you're having with no code to view. Link to comment https://forums.phpfreaks.com/topic/114397-sort-images-in-php-with-array/#findComment-588285 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.