Home >php教程 >php手册 >Sort array by first letter

Sort array by first letter

WBOY
WBOYOriginal
2016-09-03 00:00:411430browse

母 // Press the first letter 压 Foreach ($ res as $ k = & gt; $ v) {

$ res [$ k] ['first'] = StrToupper (Substr (trim ($ v ['name']) , 0, 1));
                         $arr = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', ' J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V' , 'W', 'x', 'y', 'z');
// If it is not a letter, plan him to 0-9 queue
if (! In_array ($ res [$ k] ['first'], $arr))
                                                                                                                                                                                                        )
                                                                                                                 ​$v['first']][] = $v;
                                                                                                                                                     $v;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn