I have a php array
Array
(
[0] => Array
(
[MF_B302] => Array
(
[FAILURE_DATE] => 2010-02-01 0开发者_开发技巧0:00:00
)
[0] => Array
(
[claimnum] => 1
)
)
[1] => Array
(
[MF_B302] => Array
(
[FAILURE_DATE] => 2009-08-10 00:00:00
)
[0] => Array
(
[claimnum] => 2
)
)
)
i need to sort that according to [FAILURE_DATE], does any one have a function to do this?
thank you...
This should help you brush up on the basics of array sorting in PHP
http://www.the-art-of-web.com/php/sortarray/
Something like this would sort your problem however:
usort($array, "cmp");
function cmp($a, $b){
return strcmp($b['FAILURE_DATE'], $a['FAILURE_DATE']);
}
function failureDateSort($a, $b)
{
$aDate = strtotime($a['MF_B302']['FAILURE_DATE']);
$bdate = strtotime($b['MF_B302']['FAILURE_DATE']);
if ($aDate == $bDate) {
return 0;
}
return ($aDate < $bDate) ? -1 : 1;
}
usort($myArray, "failureDateSort");
精彩评论