Re: PHP: Mulitiple Arrary Sort
| From: | Jim Lucas | Date: | Wed, 03 Sep 2008 18:31:29 +0000 |
| Subject: | Re: PHP: Mulitiple Arrary Sort | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-279435@lists.php.net to get a copy of this message | ||
Vernon wrote:
Ok, I've gotten the following so far, which is giving me the results, except it is still sorting by file name and not the file's date. <?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 ) { $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 $filemtimesThat is because you have to build the array, then sort it, then use it. you are building, using { sorting } So, move the if ( array_multisort() ) call out side and after the foreach loop -- 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# http://php.net/array-multisort Example #3if (array_multisort($filemtimes, SORT_DESC, $sorting_list) ) { echo date("m-d-Y", filemtime($file)) . " " . $file . "<br />\n"; } } } else { echo 'Directory listing call failed!'; } ?> Thanks