Re: how does array_multisort work?(!??)

From: Date: Fri, 19 Mar 2004 12:59:15 +0000
Subject: Re: how does array_multisort work?(!??)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-180953@lists.php.net to get a copy of this message
David T-G wrote:
Hi, all -- I have an array like $a =
    array
    (
      'key' =>
        array
        (
          'title' => "Topic Title",
          'content' => "Topic Content",
        ),
        ...
    ) ;
and I'd like to sort the whole thing not on the keys but on the titles. It sounds like array_multisort should do exactly what I want, but I can't seem to get it to work.
usort is what you need: function cmp($a, $b) { if ($a['title'] == $b['title']) {
       return 0;
} return ($a['title'] < $b['title']) ? -1 : 1; } usort($a, "cmp");

« previous php.general (#180953) next »