I have a multidimensional array which contains data that has date fields. Some indexes may have single date fields, others may have multiple. An example of an index with multiple date is listed below.
Array ( [0] => Array (
[0] => Array ()
... ... ...
[21] => Array (
[0] => Array (
[Date] => 2011-05-12
[Color] => green
[State] => Ohio
)
[1] => Array (
[Date] => 1999-01-23
[Color] => red
[State] => Vermont
)
[2] => Array (
[Date] => 3001-08-24
[Color] => yellow
[State] => Alaska
)
I am trying to list them as the most current date to be the first entry down to the oldest entry. For example
Array ( [0] => Array (
[0] => Array ()
... ... ...
[21] => Array (
[0] => Array (
[Date] => 3001-08-24
[Color] => yellow
[State] => Alaska
)
[1] => Array (
[Date] => 2011-05-12
[Color] => green
[State] => Ohio
)
[2] => Array (
[Date] => 1999-01-23
[Color] => red
[State] => Vermont
)
I have tried
function date_compare($a, $b){
$t1 = strtotime($a["Date"]);
$t2 = strtotime($b["Date"]);
return $t2 - $t1;
}
I get an error of
Notice: Undefined index: Date in date_compare() for both lines of $t1 and $t2
And when I put
function date_compare($a, $b){
$t1 = strtotime($a[0]["Date"]);
$t2 = strtotime($b[0]["Date"]);
return $t2 - $t1;
}
I get an error of
Notice: Undefined offset: 0 in date_compare(). On the second line $t2.
Note: The Array starts off with a [0] index, then it goes into [0], [1], [2].