vchris 3 Posted August 27, 2007 Report Share Posted August 27, 2007 I have a script that currently gets all the jpg files in a directory and then I sort them. <?php$thumbslist = array();$counter = 0;$dir = "../images/websites"; $dh = opendir($dir); while (($filename = readdir($dh)) !== false) { if(strstr($filename, '.jpg')) { //images can only be jpg $thumbslist[$counter] = $filename; $counter++; }}closedir($dh); sort($thumbslist); for($i = 0; $i <= count($thumbslist); $i++){ echo $thumbslist[$i].'<br />';}?> Is there a way I could use to order them a certain way but that I could choose? It's always by groups of 2, 1 is small and the other is the large version. Quote Link to post Share on other sites
justsomeguy 1,135 Posted August 27, 2007 Report Share Posted August 27, 2007 You can use the usort function to sort based on a user-defined function that you define to compare the values however you want.http://www.php.net/manual/en/function.usort.phpLook at the list of functions under "See also" for variations on sorting arrays. Quote Link to post Share on other sites
vchris 3 Posted August 27, 2007 Author Report Share Posted August 27, 2007 hmmm k but what about if the values are image file names. Those images are websites I've created, I want to order them by order of creation. I'm not sure how the user-defined sorting would work.edit: I found a way to sort by keys instead. This should work pretty good. I'll give it a try.http://ca.php.net/ksort Quote Link to post Share on other sites
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.