0

I have a multidimensional array and I need to sort the rows by the FAILURE_DATE value within the MF_B302 column.

[
    [
        'MF_B302' => ['FAILURE_DATE' => '2010-02-01 00:00:00'],
        0 => ['claimnum' => 1]
    ],
    [
        'MF_B302' => ['FAILURE_DATE' => '2009-08-10 00:00:00'],
        0 => ['claimnum' => 2]
    ]
]

How do I do this?

0

2 Answers 2

3

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']); 
}
0
1
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");

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.