I have a folder of XML files that look like this, all with different timestamps
<?xml version="1.0"?>
<comment>
<timestamp>1390601221</timestamp>
</comment>
I'm using the glob
function to put all of these into an array
$xmls = glob("xml/*.xml");
Then I'm trying to put the timestamp value and xml path into a new array so I can sort by the timestamp. This is how I'm doing it.
$sorted_xmls = array();
foreach ($xmls as $xml) {
$raw_xml = file_get_contents($xml);
$data = simplexml_load_string($raw_xml);
$time = $data->timestamp;
array_push($sorted_xmls, array($time, $xml));
}
All of this seems to work fine. Now I want to sort by timestamp. With the newest first.
foreach ($sorted_xmls as $key => $row) {
$final_sorted[$key] = $row[0];
}
array_multisort($final_sorted, SORT_ASC);
It doesn't seem to be working as expected. Am I doing something wrong? I assume it's on the sorting portion