Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How can I sort this first by Member id and then by Payment date?

Array
(
    [240] => Array
        (
            [Member] => Array
                (
                    [id] => 112
                )

            [Payment] => Array
                (
                    [date] => 0712


)
    )

I tried with multisort, but I never found a way what was working and all examples I found didn't had my additional level.

share|improve this question
    
look at this post : stackoverflow.com/questions/2910611/… –  ppm blackhat Jul 26 '12 at 15:02
add comment

2 Answers

Is the date value a string or an integer?

Anyway, supposing that date is an int, you could try this:

function my_sort($val1, $val2) {
    $compare_id = $val1['Member']['id'] - $val2['Member']['id'];
    if($compare_id == 0) {
        return $val1['Payment']['date'] - $val2['Payment']['date'];
    }
    else return $compare_id;
}

and then call:

usort($array, 'my_sort');
share|improve this answer
add comment

If the data is received from database you can use ... ORDER BY member,date

share|improve this answer
    
And, from the looks of it, you're using CakePHP? You just have to include those in your array (at the same level as 'conditions') –  tigertrussell Jul 26 '12 at 15:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.