Short display images by date newer to older in PHP -


i'm using following function read directory , show images gallery, works well, need display images ordering date newer older.

knows how using method?

function getpictures() {           global $page, $per_page, $has_previous, $has_next;         if ( $handle = opendir("saved/2013") ) {             $lightbox = rand();              $count = 0;             $skip = $page * $per_page;               if ( $skip != 0 )                 $has_previous = true;              while ( $count < $skip && ($file = readdir($handle)) !== false ) {                 if ( !is_dir($file) && ($type = getpicturetype($file)) != '' )                     $count++;             }             $count = 0;             while ( $count < $per_page && ($file = readdir($handle)) !== false ) {                 if ( !is_dir($file) && ($type = getpicturetype($file)) != '' ) {                     if ( ! is_dir('saved/2013') ) {                         mkdir('saved/2013');                     }                       $strfilename = "saved/2013/".$file;                     echo '<div id="imagen-t">';                     echo '<p>' .date( "d d m y g:i a", filemtime($strfilename)) . "</p>";                     echo '<p><a href="saved/2013/'.$file.'" rel="lightbox['.$lightbox.']"><img src=saved/2013/'.$file.' alt="" width="220" /></a></p>';                     echo '</div>';                     $count++;                 }             }               while ( ($file = readdir($handle)) !== false ) {                 if ( !is_dir($file) && ($type = getpicturetype($file)) != '' ) {                     $has_next = true;                     break;                 }             }         }     } 

here result: http://www.espigoplatja.com/whale/galeria/

salutations, gonzalo

have looked @ usort: http://php.net/manual/en/function.usort.php allows sort array values user defined comparison function.

an example

<?php function my_sort($a,$b) { if ($a==$b) return 0;    return ($a<$b)?-1:1; }  $a=array(4,2,8,6); usort($a,"my_sort");  $arrlength=count($a); for($x=0;$x<$arrlength;$x++)    {    echo $a[$x];    echo "<br>";    }  ?> 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -