I see much simpler solutions, but here was my initial thought:
function cmp($a, $b) { $comp1 = explode('-', $a); $comp2 = explode('-', $b); $year1 = (int) $comp1[0]; $year2 = (int) $comp2[0]; $week1 = (int) $comp1[1]; $week2 = (int) $comp2[1]; if ($year1 == $year2 && $week1 == $week2) { return 0; } elseif ($year1 == $year2) { return ($week1 < $week2) ? -1 : 1; } else { return ($year1 < $year2) ? -1 : 1; } } $array = array('2011-21', '2011-3', '2011-44', '2011-45'); uasort($array, 'cmp');
Jason source share