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

Sort array by first letter

WBOY
Release: 2016-09-03 00:00:41
Original
1426 people have browsed it

母 // 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;

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template