Page 1 of 1

Multi-dimensional array sorting guidance needed...

Posted: Sun May 25, 2008 11:43 pm
by Peuplarchie
Good day to you,
I have an multi-dimensional array and I need to sort it by date and then height.

My question is how would I build my code to do such a function ?

Here is how I have built my array :

Code: Select all

 
 
<?php
 
 
$imgdir= $_GET['folder'];
$imgdir.="/";
 
 
 
function dircont($imgdir)
 {
     $dir_array = array();
     if (false !== ($dir = opendir($imgdir)))
     {
         while (false !== ($file = readdir($dir)))
         {
             if ($file != '.' && $file != '..')
             {
                 $fInfo = array();
                 $fInfo[] = $file;
                 if (($imageInfo = @getImageSize($imgdir."".$file)) !== false)
                 {
                     $fInfo['width'] = $imageInfo[0];
                     $fInfo['height'] = $imageInfo[1];
                 }
                 
                 if (($stat = stat($imgdir."".$file)) !== false)
                 {
                     $fInfo['mtime'] = $stat['mtime'];
                     // Lol, forgot to put the size in :P
                     $fInfo['size'] = $stat['size'];
                 }
                 
                 $dir_array[] = $fInfo;
             }
         }
         return $dir_array;
     }
     else
     {
         return false;
     }
 }  
 
 
 
 
 // To print..
 echo "<pre>";
 print_r(dircont($imgdir));
 echo "</pre>";
 
 
?> 
 
 

Re: Multi-dimensional array sorting guidance needed...

Posted: Mon May 26, 2008 10:20 am
by pickle
Look into array_multisort().