//排序
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. 表驱动方法(Table-Driven Methods)

    表驱动方法(Table-Driven Methods) - winner_0715 - 博客园 https://www.cnblogs.com/winner-0715/p/9382048.html W ...

  2. 转:解决tomcat服务器跨域问题

    原文地址: 解决tomcat服务器跨域请求问题 注:还未测试 在tomcat 的web.xml 配置文件中加入如下配置过滤器 (如web.xml中有多个filter时要把下面配置放在最前端) < ...

  3. C++11 vector使用emplace_back代替push_back

    C++11中,针对顺序容器(如vector.deque.list),新标准引入了三个新成员:emplace_front.emplace和emplace_back,这些操作构造而不是拷贝元素.这些操作分 ...

  4. 【Python全栈-后端开发】Django进阶2-Form表单

    Django进阶2-Form表单 Django的Form主要具有一下几大功能: 生成HTML标签(可以保留上次输入内容) 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页 ...

  5. 【查阅】教你使用SQL SERVER复制

    关键词:复制,复制总结,复制汇总,复制查阅 1.概念与搭建 Step1:SQL SERVER复制介绍 Step2:SQL Server 复制事务发布 Step3:SQL Server 通过备份文件初始 ...

  6. 编程实现类似Linux系统的cp功能

    选做题目以及分析 题目:编写MyCP.java 实现类似Linux下cp XXX1 XXX2的功能,要求MyCP支持两个参数: java MyCP -tx XXX1.txt XXX2.bin 用来把文 ...

  7. jQuery学习--Code Organization Concepts

    jQuery官方文档:  http://learn.jquery.com/code-organization/concepts/ Code Organization Concepts(代码组织概念) ...

  8. python中使用os.path.join()

    os.path.join的详细解释请移步os.path模块在使用的过程中,我使用如下代码: import ospath = "F:/gts/gtsdate/"b = os.path ...

  9. 当业务逻辑没错,直接mapper里面出错时

    仔细检查,发现sql语句写的也没问题,但就是出错 slide_show_img_url = #{slideShowImgUrl,jdbcType=VARCHAR}, where goods_slide ...

  10. centos----------centos下如何安装phpstorm

    1.首先打开centos下的谷歌浏览器,找到phpstorm官网下载linux版本.PhpStorm-2016.3.2.tar.gz 2.然后gunzip PhpStorm-2016.3.2.tar. ...