I'm trying to order my XML by date but code doesn't work well. Here is my code
$xml = simplexml_load_file ('http://xml.dsautoestoque.com/?l=09086369000133'); $arr=array(); foreach($xml->veiculo as $aTask) { $arr[]=$aTask; } usort($arr, function($a, $b) { $ad = new DateTime($a['cadastro']); $bd = new DateTime($b['cadastro']); if ($ad == $bd) { return 0; } return $ad > $bd ? 1 : -1; }); I did like this
foreach($arr as $aTask) {
$data1 = $aTask->cadastro; }
But is not returning by date, it is returning this 03/08/2015 18:22 24/11/2015 11:16 22/10/2015 17:36
No comments:
Post a Comment