There is an array

Array ( [0] => Array ( [nameUser] => Я ) [1] => Array ( [nameUser] => К ) ) 

It is required to sort it by the nameUser field, so that it will end up

 Array ( [1] => Array ( [nameUser] => Я ) [0] => Array ( [nameUser] => К ) ) 
  • one
    array_multisort can be zayuzat if desired, but as for me it is better to write conditions in the request to the database. Type order by nameUser desc - Boris Pobezhimov
  • use the usort() - write your sorting nameUser , which would compare the values ​​of the nameUser field to return -1, 0 or 1. - Sergiks
  • Heh, just forgot, in a mysql query, you can do the sorting by fields. I do not know whether to delete the question or not? All the same, the solution is interesting. - Denis Kotlyarov

1 answer 1

I did not see the answer, I climbed on the Internet and found it.

 usort($array, function($a, $b){ return strcasecmp($a['nameUser'], $b['nameUser']); }); return $array;