Ciao a tutti dovrei ordinare tutte le array dello script che vi posto qui sotto in ordine alfabetico, sto impazzendo e nn ci riesco proprio help help help

Codice PHP:

<?php

function getlastfile($dir)
 {
   
$dirarr[]="";
   if(!(
$dp opendir($dir)))
    die(
"woops");
    while(
$file readdir($dp))
      if(
$file != '.' && $file != '..')     
        
array_push($dirarr,$file);
   
$size=sizeof($dirarr)-1;
 return 
$dirarr[$size];
 }

// Note to self nodisp variable is simply for looks it serves no real purpose in the function 
// it is false if the last directory is the currenty directory being traversed
function traverse_dir($dirp,$dir_array,$nodisp)
{
  global 
$PHP_SELF;
  static 
$loop=1;
  
$size = (sizeof($dir_array) - 1);
  
$d=rawurlencode(implode("*",$dir_array));
  
$dirp .= "/" $dir_array[$loop];
  
$Ivar "images/tree_split.gif";
  if(
$loop $size)
   
$dircheck $loop +1;
  else 
   
$dircheck $loop;
  

 
$var2 ="";

  for(
$iloop=0$iloop $loop$iloop++)
     
$var2 .="[img]images/tree_vertline.gif[/img]";
    if(
$nodisp == 0)
      
$var2 substr($var2,36) . " &nbsp&nbsp&nbsp";  
 
  if(!(
$dp opendir($dirp)))
    die(
"Sorry, Page cannot be displayed "); //<script>history.go(-1)</script>");
  
$lastfile getlastfile($dirp);
   while(
$file readdir($dp))
      if(
$file != '.' && $file != '..')     
       {
         
         if(
$lastfile == $file)
             
$Ivar "images/tree_end.gif";
         if(
$lastfile == $file && $lastfile == $dir_array[$size])
             
$nodisp 0;
         
$files filesize("$dirp/$file");
         
$filep rawurlencode($file);
         
// This checks to see if there are anymore sub directories in the dir_array that have not yet been traversed  
          
if(is_dir("$dirp/$file") &&  ("$dirp/$dir_array[$dircheck]== "$dirp/$file") )
            { 
              echo 
"<tr>$var2<img src=$Ivar>[url='$PHP_SELF?closed=1&fold=$filep&d=$d#$dirp/$file'][img]images\folderopen.gif[/img][/url][url='$PHP_SELF?closed=1&fold=$filep&d=$d#$dirp/$file'][b]$file[/b][/url]</tr>";
              
$loop++;
                
traverse_dir($dirp,$dir_array,$nodisp); 
            }
          else if(
is_dir("$dirp/$file"))
            echo 
"<tr>$var2<img src=$Ivar>[url='$PHP_SELF?opened=1&fold=$filep&d=$d#$dirp/$file'][img]images\folder.gif[/img][/url][url='$PHP_SELF?opened=1&fold=$filep&d=$d#$dirp/$file'][b]$file[/b][/url]</tr>";
          else
            echo 
"<tr>$var2<img src=$Ivar>[url='$dirp/$file'][img]images\file.gif[/img][/url][url='$dirp/$file']$file[/url]</tr>"
 
      }

  
$loop++;
 return 
0;
}


?>
<?php
if(!isset($fold))
 
$fold="";
?>

 
   
<?php
/******************** Define Variables for main code ****************************/
 // Declare some variables that are going to be needed later on


  
$basedir="Archivio";   
   if(!isset(
$d))
    
$d="";
   else
    {
      
$d rawurldecode($d);
      
$dir_array2 explode("*",$d);
    }
   if(!isset(
$dir_array2))
     
$dir_array2[0] = $basedir;

    
$dir_array $dir_array2;
    
$dir $dir_array[0]; 

   if(!isset(
$opened))
     
$opened 0;
   else
     
$opened 1;
   if(!isset(
$closed))
     
$closed 0;
   else
     
$closed 1;
   
   if(
$basedir != $dir_array[0])
      die(
"Sorry, Page cannot be displayed "); //<script>history.go(-1)</script>");
  

/*********************************************************************************/
 // That should be good enough next define what to do if a directory has been opened or closed

   
if($closed == 1)
    {
      
$fold rawurldecode($fold);      
      
$size2 sizeof($dir_array)-1;
       while(
$dir_array[$size2] != $fold)
        {
         
array_pop($dir_array); 
         
$size2--;
        }
       
array_pop($dir_array);
      
$opened =1;
    }     

   if(
$opened == 1)
    {
     if(
$closed != 1)
      {
       
$fold rawurldecode($fold);
       
$dir_array[] = $fold;
      }
 
// Above we just added the new folder on and we are going to check and see if it the array still makes a vaild directory. If it doesn't - unload the array back to the base directory and add the new folder on again.
   
        
$tmp_dir implode("/" $dir_array);
        if(!(
$tmp = @opendir($tmp_dir)))
          {
           
$size2 sizeof($dir_array) - 1;
             while(!(
$tmp = @opendir($tmp_dir)))
               {
                 
array_pop($dir_array);
                 
array_pop($dir_array);
                  
$dir_array[] = $fold;
                  
$tmp_dir implode("/" $dir_array);
               }
          }
     }

/*********************************************************************************************/
?>
<tr>
    <td></td>
</tr>
<table  width="100%" >
 
    <?php
/*********************************************************************************************/




// Thats it for the opened and closed code we need now were going to execute the initial directory traversion on the base directory.


if(sizeof($dir_array)-== 0)
 
$size 0;
else
 
$size 1;

  if(!(
$dp opendir($dir)))
    die(
"Sorry, Page cannot be displayed "); //<script>history.go(-1)</script>");
  
$lastfile getlastfile($dir); 
  
$d=rawurlencode(implode("*",$dir_array));
  
$Ivar "images/tree_split.gif";
  echo 
"<tr>[url='$PHP_SELF'][img]images/drive.gif[/img][/url][b][url='$PHP_SELF'][/url][/b]</tr>";
    while(
$file readdir($dp))
      if(
$file != '.' && $file != '..')     
        { 
          
$files filesize("$dir/$file");
          
$filep rawurlencode($file);
           if(
$lastfile == $file)
             
$Ivar "images/tree_end.gif";
           if( (
is_dir("$dir/$file")) && ("$dir/$dir_array[$size]== "$dir/$file") )
             {
               echo 
"<tr><img src=$Ivar>[url='$PHP_SELF?closed=1&fold=$filep&d=$d'][img]images\folderopen.gif[/img][/url][b][url='$PHP_SELF?closed=1&fold=$filep&d=$d']$file[/url][/b]</tr>";
                
traverse_dir($dir,$dir_array,1);
              }
             
           else if(
is_dir("$dir/$file"))
             echo 
"<tr><img src=$Ivar>[url='$PHP_SELF?opened=1&fold=$filep&d=$d'][img]images\folder.gif[/img][/url][b][url='$PHP_SELF?opened=1&fold=$filep&d=$d']$file[/url][/b]</tr>";            
           else
             echo 
"<tr><img src=$Ivar>[url='$basedir/$file'][img]images\file.gif[/img][/url][url='$basedir/$file']$file[/url]</tr>";
         }


?>