不区分大小写的排序数组 [英] Case insensitive sort array

查看:113
本文介绍了不区分大小写的排序数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前段时间找上阵列线程排序我想出了以下内容:

Some time ago looking on the threads on array sorting I had come up with the following:

public function sortList(&$objects, $on, $order = 'ASC') {
    $comparer = ($order === 'DESC') 
    ? "return -strcmp(\$a->{$on},\$b->{$on});" 
    : "return strcmp(\$a->{$on},\$b->{$on});"; 
usort($objects, create_function('$a,$b', $comparer)); 
return $objects;
}

以上code工作得很好,唯一的问题是,它是区分大小写的,而我想它是区分大小写。
这将无需重写整个事情可能吗?

The above code works fine, the only problem is that it is case sensitive, whereas I'd like it to be case insensitive. Would it be possible without rewriting the whole thing?

推荐答案

使用 strcasecmp 代替STRCMP的

Use strcasecmp instead of strcmp.

这篇关于不区分大小写的排序数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆