murratw Posted June 25, 2012 Share Posted June 25, 2012 I need help modifying the following code. The following code displays the latest 15 images in reverse chronological order. I would like to display the latest 15 images in random order. Can someone help me modify? <?php //Your folder $files = glob("images/*.*"); function sortnewestfilesfirst($a, $b) { return filemtime($b) - filemtime($a); } usort($files, "sortnewestfilesfirst"); $colCnt=0; echo '<table border="0" style="width:2000px;">'; for ($i=0;$i<15;$i++) { $colCnt++; if ($colCnt==1) echo '<tr>'; echo '<td width="20%" style="font-size:8.5px; font-family:arial">'; $num = $files[$i]; echo ' <div class="ImgBorder"> <div class="clipout"> <div class="clipin"> <a href="' . $num . '" rel="lightbox[all]"><img class="thumb ImgBorder" src="'.$num.'"> </a> </div> </div></div>'." "; echo '</td>'; if ($colCnt==2) { echo '</tr>'; $colCnt=0; } } echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/264765-simple-image-sorting/ Share on other sites More sharing options...
xyph Posted June 25, 2012 Share Posted June 25, 2012 Just array_slice and shuffle Quote Link to comment https://forums.phpfreaks.com/topic/264765-simple-image-sorting/#findComment-1356935 Share on other sites More sharing options...
murratw Posted June 25, 2012 Author Share Posted June 25, 2012 Thank you for the reply. but how do I do that? I am very new to this. Quote Link to comment https://forums.phpfreaks.com/topic/264765-simple-image-sorting/#findComment-1356945 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.