Re: PHP: Mulitiple Arrary Sort
| From: | Jim Lucas | Date: | Wed, 03 Sep 2008 21:32:24 +0000 |
| Subject: | Re: PHP: Mulitiple Arrary Sort | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-279453@lists.php.net to get a copy of this message | ||
Vernon wrote:
I'm really starting to feel incompitant here. Sorry to ask, but could you show me what you mean?<?php $folder = $_GET['id']; $dir = "/home/recruitsavvy/public_html/resumes/$folder/"; $filepattern = '*'; $sorting_list = array(); $filemtimes = array(); # Get file/dir listing, else error message if ( ( $list = glob( $dir . $filepattern ) ) !== false ) { foreach ( $list AS $file ) {
# Get file modification time in Unix Time (seconds)
$filemtime = filemtime( $dir . $file );
# Build array to be sorted with filename and filemtime
$sorting_list[] = array('filename' => $file, 'filemtime' => $filemtime);
# This is the list of filemtimes to sort by later
$filemtimes[] = $filemtime;
}
# Sort array based on $filemtimes
# http://php.net/array-multisort Example #3array_multisort($filemtimes, SORT_DESC, $sorting_list); # Now loop/echo each one foreach ( $sorting_list AS $entry ) {
echo date("m-d-Y", $entry['filemtime']) . " {$file}<br />\n";
}
} else {
echo 'Directory listing call failed!';
}
?>
If this works for you, please post a SOLVED labeled solution back to the list so others will learn from this too.
Thanks
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare