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!
There are two ways:
Create a new array (like $files) but don't just save the filename into it. Create for each entry in $files a new array with 2 elements, first element is the filetime (filectime()), second the filename ($file).
$files = array();
//open dir etc.
while(...) {
$files[] = array(filectime($file), $file);
//Compares the filectime of to two files
function fileCompare($a, $b) {
return $a[0] - $b[0];
}
usort($files, "fileCompare");
//print $files
The other would be to call filectime() in the fileCompare function:
$files = array();
//Your old while loop
while(...) {
$files[] = $file;
//Compares the filectime of to two files
function fileCompare($a, $b) {
return filectime($a) - filectime($b);
}
usort($files, "fileCompare");
//print $files
Last edited by Hannes2k on Sat Oct 25, 2008 3:16 pm, edited 1 time in total.
Ok, now im confused. Site made for funny pictures (upload allowed for all with admin confirmation). I tried to aply your exaple, but it ordered everything from about center of all photos.
P.S. If this will not work ill make it with MySQL database.
In the first example there had been a small mistake, the index of $a and $b in the compare function have to be 0 not 1.
But this code should worke fine (but I didn't tested it)
One more thing. I'm making site chat. Need help with Links that people will post, they use " Link name ".
I used str_replace for another tags, but i think i need preg_match or preg_replace now...