//排序
public function getFirstChar($s){

$s0 = mb_substr($s,0,3); //获取名字的姓

$s = iconv('UTF-8','gb2312', $s0); //将UTF-8转换成GB2312编码

$x =ord($s0);

if (ord($s0)>128) { //汉字开头,汉字没有以U、V开头的

$asc=ord($s{0})*256+ord($s{1})-65536;

if($asc>=-20319 and $asc<=-20284)return "A";

if($asc>=-20283 and $asc<=-19776)return "B";

if($asc>=-19775 and $asc<=-19219)return "C";

if($asc>=-19218 and $asc<=-18711)return "D";

if($asc>=-18710 and $asc<=-18527)return "E";

if($asc>=-18526 and $asc<=-18240)return "F";

if($asc>=-18239 and $asc<=-17760)return "G";

if($asc>=-17759 and $asc<=-17248)return "H";

if($asc>=-17247 and $asc<=-17418)return "I";

if($asc>=-17417 and $asc<=-16475)return "J";

if($asc>=-16474 and $asc<=-16213)return "K";

if($asc>=-16212 and $asc<=-15641)return "L";

if($asc>=-15640 and $asc<=-15166)return "M";

if($asc>=-15165 and $asc<=-14923)return "N";

if($asc>=-14922 and $asc<=-14915)return "O";

if($asc>=-14914 and $asc<=-14631)return "P";

if($asc>=-14630 and $asc<=-14150)return "Q";

if($asc>=-14149 and $asc<=-14091)return "R";

if($asc>=-14090 and $asc<=-13319)return "S";

if($asc>=-13318 and $asc<=-12839)return "T";

if($asc>=-12838 and $asc<=-12557)return "W";

if($asc>=-12556 and $asc<=-11848)return "X";

if($asc>=-11847 and $asc<=-11056)return "Y";

if($asc>=-11055 and $asc<=-10247)return "Z";

}else if(ord($s)>=48 and ord($s)<=57){ //数字开头

switch(iconv_substr($s,0,1,'utf-8')){

case 1:return "Y";

case 2:return "E";

case 3:return "S";

case 4:return "S";

case 5:return "W";

case 6:return "L";

case 7:return "Q";

case 8:return "B";

case 9:return "J";

case 0:return "L";

}

}else if(ord($s)>=65 and ord($s)<=90){ //大写英文开头

return substr($s,0,1);

}else if(ord($s)>=97 and ord($s)<=122){ //小写英文开头

return strtoupper(substr($s,0,1));

}

else

{

return iconv_substr($s0,0,1,'utf-8');

//中英混合的词语,不适合上面的各种情况,因此直接提取首个字符即可

}

}
// 拼友列表
public function doPageFriend(){
global $_GPC,$_W;
$uniacid = $_W['uniacid'];
$friends = pdo_fetchall("SELECT * FROM ".tablename("pinba_pinyou")."where uniacid=:uniacid",array(":uniacid"=>$uniacid));
foreach($friends as &$value){

$userName[] = array("name"=>$value['x_name'],"thumb"=>$_W['attachurl'].$value['x_thumb']);
}

$charArray = $this->addPeople($userName);

return $this->result(0,"success",$charArray);
}
public function addPeople($userName)

{

sort($userName);
foreach($userName as &$name){

$char = $this->getFirstChar($name['name']);

$nameArray = array();

if(count($charArray[$char])!=0){

$nameArray = $charArray[$char];
}

array_push($nameArray,$name);

$charArray[$char] = $nameArray;

}

ksort($charArray);

return $charArray;

}

前台显示

<block wx:for="{{friends}}" wx:key="gro" wx:for-item="group" data-index="{{index}}">
<view class="flex" id="{{group.groupName}}">
<view class="group-name"><text>{{index}}</text></view>
<view class="flex group-users">
<view wx:for="{{group}}" wx:key="ss" wx:for-item="user" wx:for-index="idx" class="user box box-lr" bindtap='pinyou_Xq' data-id='{{id}}'>
<view class="user-avatar box box-lr box-pack-center box-align-center">
<image class="user-avatar-img" src="{{user.thumb}}"></image>
</view>
<view class="flex user-name font28">{{user.name}}</view>
</view>
</view>
</view>
</block>

php 按照中文字母名字排序,并把相应的头像显示出来的更多相关文章

  1. js中实现中文按字母拼音排序

    js中实现中文按字母拼音排序 var Pinyin = (function (){ var Pinyin = function (ops){ this.initialize(ops); }, opti ...

  2. IOS数组按中文关键字以字母序排序

    本文转载至 http://blog.csdn.net/xunyn/article/details/7882087 iosobjective cuser框架通讯 IOS项目中会用到对通讯录的联系人或是会 ...

  3. php里获取第一个中文首字母并排序

    需求里结算首页需要按门店的首字母A-Z排序.我的数据结构原本是这样的: Array ( [0] => Array ( [sid] => 2885842 [recetcstoredpay] ...

  4. 本地化下按首字母分组排序的神器——UILocalizedIndexedCollation

    最近在整一个很简单的通讯录相关的项目,通讯录当然就少不了按首字母或者汉字拼音首字母分组排序索引.因为按照我一贯的的做法,都是想要做成更通用的.支持本地化的,所以这就纠结了,世界各地的语言啊我去,我顶多 ...

  5. 在PHP中,将一个汉字数组按照拼音首字母进行排序

    (之前发的这篇博文因为含有敏感关键字,只好重发一遍了) <?php $str = "我们可以在浏览器中看到,当鼠标移到元素上时,元素开始向右移动,开始比较慢,之后则比较快,移开时按原曲 ...

  6. PHP读取文件夹目录,按时间排序,大小排序,名字排序

    工作中有时候会遇到文件存储数据,但是在前台显示的时候又因为没有数据库,无法使用上传或最后一次修改日期字段排序,所以有了如下代码: <?php $dir = "./";//目录 ...

  7. sql server 利用首字母拼音排序和笔画排序的语句

    --按笔画排序 select * from Student order by Sname COLLATE Chinese_PRC_Stroke_CS_AS_KS_WS --按字母拼音排序 select ...

  8. localeCompare() 方法实现中文的拼音排序

    google了很多次才发现在国外网站上有提示如何比较中文,原文地址:http://www.webdeveloper.com/forum/showthread.php?t=9365 前提:使用Unico ...

  9. Oracle 如何对中文字段进行排序

    Oracle 如何对中文字段进行排序 oracle中drop.delete和truncate的区别 oracle里的执行计划-查看

随机推荐

  1. 日期控件——my97

    一.官网 http://www.my97.net/index.asp 下载: //下文已更新与bootstrap样式的结合 二.demo演示 实际使用时请注意文件引入的实际位置: [补充] 数据库字段 ...

  2. (转载)Java Map中的Value值如何做到可以为任意类型的值

    转载地址:http://www.importnew.com/15556.html     如有侵权,请联系作者及时删除. 搬到我的博客来,有空细细品味,把玩. 本文由 ImportNew - shut ...

  3. java框架之SpringBoot(15)-安全及整合SpringSecurity

    SpringSecurity介绍 Spring Security 是针对 Spring 项目的安全框架,也是 Spring Boot 底层安全模块默认的技术选型.它可以实现强大的 Web 安全控制.对 ...

  4. 小程序 切换到tabBar页面不刷新问题

    小程序跳转的几种方式有wx.navigateTo,wx.redirectTo,wx.reLaunch,wx.switchTab等.下面我们重点研究切换到tabBar的两种方式. wx.switchTa ...

  5. 2018-2019-1 20189203《Linux内核原理与分析》第二周作业

    一.本周学习情况 我本周结合<庖丁解牛>教材学习了蓝墨云的视频课,主要学习内容如下: 1.学习了计算机的工作原理,深入理解了冯诺依曼体系结构. 2.学习了X86-32 CPU的寄存器 3. ...

  6. Could not open JDBC Connection for transaction; nested exception is com.alibaba.druid.pool.GetConnection

    Could not open JDBC Connection for transaction; nested exception is com.alibaba.druid.pool.GetConnec ...

  7. sublime-text3按tab跳出括号

    功能 通过按tab自动跳过右括号,右引号,虽然也可以按右方向键,但离得太远按起来太麻烦 在首选项->按键绑定里添加: { "keys": ["tab"], ...

  8. WSDL文档结构图

  9. Java连接数据库 #06# SQL与代码分离(精化版本)

    索引 DAO层依赖关系草图 应用示例 接Java连接数据库#05#,对代码进行改进. DAO层依赖关系草图 应用示例(只需3步!) 1.首先定义接口类: package org.sample.shop ...

  10. C++如何在r3静态调用NT函数

    原文最早发表于百度空间2010-02-22. 1.把ntapi.h.ntdll.lib放在一个目录,然后设置工具——选项——项目和解决方案——VC++目录——包含文件,把刚刚的目录设置在改包 含文件中 ...