Sort an array of dates using usort() and sort() functions by the timestamp converted by mktime()
<p>I have an array of dates and I have to sort it by using the described functions.</p>

<p>Here is what I have:</p>

<pre><code>$dates = array ('10-10-2003', '2-17-2002', '2-16-2003','1-01-2005', '10-10-2004' );
function date_to_timestamp($d){
$newarr = array();
foreach($d as $f) {
    $arr=explode("-",$f);
    array_push($newarr, mktime(0,0,0,$arr[0],$arr[1],$arr[2]));
}
return $newarr;
}

function cmp2($a, $b)
{
if ($a == $b) {
    return 0;
}
return ($a &lt; $b) ? -1 : 1;
}

$third = date_to_timestamp($dates);


usort($third, "cmp2");
print_r($third);

?&gt;
</code></pre>

<p>After that, this is the crazy output I get:</p>

<p>Array
(
    [0] => 1013922000
    [1] => 1045371600
    [2] => 1065758400
    [3] => 1097380800
    [4] => 1104555600
)</p>

<p>Where is my mistake? I will appreciate any help with solution.</p>
