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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -