Multi-dimensional array sorting guidance needed...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Multi-dimensional array sorting guidance needed...

Post 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>";
 
 
?> 
 
 
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post by pickle »

Look into array_multisort().
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply