...

View Full Version : Sorting array problem.



Peuplarchie
09-03-2007, 06:26 AM
Good day to you all,
I'm trying to have an array sort. I have try many way, and stfw.

Can somebody help me to have the following code to sort the result folder first and file after their respective folder.



<?PHP

function recur_dir($dir)
{
$dirlist = opendir($dir);
while ($file = readdir ($dirlist))
{

if ($file != '.' && $file != '..')
{
$newpath = $dir.'/'.$file;
$newpath2 = substr($newpath, 0, -4);
$newpath0 = basename($newpath2,".*");
$level = explode('/',$newpath);
if (is_dir($newpath))
{

$mod_array[] = array(
'level'=>count($level)-1,
'path'=>$newpath,
'name'=>end($level),
'kind'=>'dir',
'mod_time'=>filemtime($newpath),
'content'=>recur_dir($newpath));
rsort($mod_array);
echo '<tr><td bgcolor="#663300">';
echo '<center><b class="whhite00">'.$newpath.'</b></center></td></tr>';
echo "\n\r";
}else{

$mod_array[] = array(
'level'=>count($level)-1,
'path'=>$newpath,
'name'=>end($level),
'kind'=>'file',
'mod_time'=>filemtime($newpath),
'size'=>filesize($newpath));

echo '<tr><td bgcolor="#ffffff" onClick="if(this.bgColor==\'#0000ff\'){this.bgColor=\'#ffffff\'}else{this.bgColor=\'#0000ff\'}">';
echo '<label for="'.$newpath0.'" style="padding-right:3px;display:block;" >';
echo '<input name="checkbox[]" value="'.$newpath. '" type="checkbox" id="'.$newpath0. '" >';
echo '<img src="'.$newpath.'" width="100" ID="'.$newpath0.'" title="'.$newpath.'" alt="'.$newpath1.'"></label></td></tr>';
echo "\n\r";
}

}
}
closedir($dirlist);
return $mod_array;
}

recur_dir('Images');




?>



Thanks !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum