vchris Posted August 27, 2007 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 27, 2007 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. Link to comment Share on other sites More sharing options...
vchris Posted August 27, 2007 Author 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.