-1

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
                                )
                            )
                        )
                   )
              )
            )
Chris.C
  • 297
  • 2
  • 15

1 Answers1

0

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;
Community
  • 1
  • 1
Justinas
  • 34,232
  • 3
  • 56
  • 78