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.

This question already has an answer here:

How can I sort this array by value "date and let the ASC result shows? Is the bad formatting and naming caused my works to being wrong so that it made the ["date"] could not show in the table by ASC format. Thanks for everyone helps.

Array:

$arrayBooking = array(
        "a01"=>array(
            "Amy"=>array(
                "booking1"=>array(
                    "231"=>array(
                        "date"=>"21/08/2014",
                        "period"=>array(
                            "from"=>1,
                            "to"=>3
                            )
                        )
                    )
                )
           ),
           "a02"=>array(
              "Peter"=>array(
                "booking1"=>array(
                    "231"=>array(
                        "date"=>"23/08/2014",
                        "period"=>array(
                            "from"=>2,
                            "to"=>3
                            )
                        )
                  ),
                 "booking2"=>array(
                    "231"=>array(
                        "date2"=>"20/08/2014",
                        "period"=>array(
                            "from"=>2,
                            "to"=>5
                            )
                        )
                    )
                )
            ),
            "a05"=>array(
               "Mary"=>array(
                  "booking1"=>array(
                     "321"=>array(
                        "date"=>"22/08/2014",
                            "period"=>array(
                                "from"=>3,
                                "to"=>6
                                )
                            )
                        )
                   )
              )
            )
share|improve this question

marked as duplicate by Ja͢ck Aug 20 at 7:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
it is already sorted by date –  SKRocks Aug 20 at 7:16
    
it showed almost 2% of the array information. lol –  learn_PHP Aug 20 at 7:17
    
i got it i will try and update you –  SKRocks Aug 20 at 7:19

1 Answer 1

You can use usort() function to sort array by preferred algorithm

usort($array, function($a, $b){
    if ($a < $b) {
       return -1;
    } elseif ($a == $b) {
       return 0;
    }
    return 1;
});

To compare dates, use this SO answer

$stamp1 = strtotime($date1);
$stamp2 = strtotime($date2);

return $stamp1 - $stamp2;
share|improve this answer

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