php - Sort Multidimensional Array Alphabetically not Working? -
so have array called $links
array( [0] = array( 'type' => 'thread' 'url' => 'blah blah blah' ), [1] = array( 'type' => 'media' 'url' => 'blah blah blah' ), [2] = array( 'type' => 'website' 'url' => 'blah blah blah' ) ); what trying sort array alphabetically using "type". using usort()
usort($links, create_function('$b, $a', 'return $a["type"] - $b["type"];')); the problem is, not sorting array... reverse array. after running through, website > media > thread. if process second time, reverses thread > media > website.
the final result should media > thread > website. missing something? why not sorting correctly?
try this, instead:
usort($links, create_function('$a, $b', 'return strcmp($a["type"], $b["type"]);'));
Comments
Post a Comment