I am using to restore a database and would like to display the latest first. At the moment, it is display ad-hoc with no sort on it. I would be grateful if someone could help with this.
Many thanks
<!-- START OF RESTORE FUNCTION -->
<div id="restore">
<div id="restoreTxt">
This area is for restoring created database backups. To restore a backup, simply<br />select the backup you require and click the 'Restore Backup' button.
</div>
<select class="testdept chosen-select" id="restoredept" data-placeholder="Select a database to restore">
<option value=""></option>
<?php
$files = "sqlbackup2/*";
foreach(glob($files) as $file) {
if(!is_dir($file)) {
$output = date("m/d/Y H:i",filemtime($file));
$filebackup = $file;
echo "<option value=".basename($filebackup).">".$output."</option>";
}
}
?>
</select>
<div class="restoretxt"></div>
<input type="button" id="restoreBtn" value="Restore Backup" disabled />
<div class="rssuccesstxt"></div>
<div class="rserrortxt"></div>
<div class="rsajaxtxt"></div>
</div>
</div>
I like that better than what I was thinking of. It would be possible to create a new array using file β mtime as keys β values and use sort β ksort. But that could leave open a possible bug in the (even if remote) event that any files had the same values as other files.
If two members compare as equal, their relative order in the sorted array is undefined.
What I do like about coding like this instead of key => value is that this is quite easy to follow, whereas juggling and sorting with key => value itβs a lot easier to get lost in the details.