christian: array usort = ???

servus, befor ich hier lang rumsülze und dann falsch verstanden werde... hier das problem

Original:

Array
(
    [0] => Array
        (
            [name] => Hugo
            [date] => 2000-4-6
            [mail] => 0
            [pub] => 1
            [site] => 0
        )

[1] => Array
        (
            [name] => Hugo
            [date] => 2000-4-6
            [mail] => 0
            [pub] => 0
            [site] => 0
        )

[2] => Array
        (
            [name] => Hugo
            [date] => 1998-6-8
            [mail] => bla@bla.gg
            [pub] => 1
            [site] => 0
        )

[3] => Array
        (
            [name] => Hugo
            [date] => 1999-6-9
            [mail] => bla@bla.gg
            [pub] => 0
            [site] => Hugo
        )

)

dann:

usort($content, "cmp");
   function cmp ($a, $b) {
   return strcmp($a["date"], $b["date"]);
   }

Ergebnis:

Array
(
    [0] => Array
        (
            [name] => Hugo
            [date] => 1999-6-9
            [mail] => bla@bla.gg
            [pub] => 0
            [site] => Hugo
        )

[1] => Array
        (
            [name] => Hugo
            [date] => 1998-6-8
            [mail] => bla@bla.gg
            [pub] => 1
            [site] => 0
        )

[2] => Array
        (
            [name] => Hugo
            [date] => 2000-4-6
            [mail] => 0
            [pub] => 0
            [site] => 0
        )

[3] => Array
        (
            [name] => Hugo
            [date] => 2000-4-6
            [mail] => 0
            [pub] => 1
            [site] => 0
        )

)

wieso ist 1999 vor 1998????

  1. servus, habs:

    function cmp($a, $b) {
        if ($a[date] == $b[date]) return 0;
        return ($a[date] > $b[date])?1:-1;
       }

    usort($content, "cmp");