-2

How can I sort this array by the value of the "nume" key using usort and strcasecmp?
Thanks!

   $persoane=array(array('prenume'=>'Catalin',
                      'nume'=>'Sandu',
                      'varsta'=>21,
                      'sex'=>'m'),
                array('prenume'=>'Florina',
                      'nume'=>'Sandu',
                      'varsta'=>24,
                      'sex'=>'f'),
                array('prenume'=>'Maria',
                      'nume'=>'Ionescu',
                      'varsta'=>20,
                      'sex'=>'f'),
                array('prenume'=>'Denise',
                      'nume'=>'Rifai',
                      'varsta'=>28,
                      'sex'=>'f'),
                array('prenume'=>'Nelson',
                      'nume'=>'Mondialu',
                      'varsta'=>69,
                      'sex'=>'m'), 

               );       
  • 2
    The best way is to [read the docs](http://www.php.net), and [try something](http://eval.in) – Elias Van Ootegem Dec 16 '14 at 15:29
  • possible duplicate of [Sort Multi-dimensional Array by Value](http://stackoverflow.com/questions/2699086/sort-multi-dimensional-array-by-value), which is _a duplicate question_, of ***a duplicate question***! do some research... come on – Elias Van Ootegem Dec 16 '14 at 15:31
  • possible duplicate of [Reference: all basic ways to sort arrays and data in PHP](http://stackoverflow.com/questions/17364127/reference-all-basic-ways-to-sort-arrays-and-data-in-php) – tsnorri Dec 16 '14 at 15:32

1 Answers1

0

Can try something like this

function u_sort($a, $b) {
    return strnatcmp($a['nume'], $b['nume']);
}
usort($persoane, 'u_sort');

print '<pre>';
print_r($persoane);
print '</pre>';

More about usort()

MH2K9
  • 11,951
  • 7
  • 32
  • 49