douliu8327 2018-10-24 00:49
浏览 739

如何在PHP中按字典顺序对列进行排序?

I am working on the website in which I want to sort everything on the basis of customer_name (which is the 1st column from the table)..

Below is my query in php code I have:

.....
.....
$y = isset($filters['items']['yaxis']) ? $filters['items']['yaxis'] : null;
$x = isset($filters['items']['xaxis']) ? $filters['items']['xaxis'] : null;

switch ($y) {
    case 'customer_name':
        $query->order( columns: $y . ' ' . (strtoupper($x) == 'DESC' ? 'DESC' : 'ASC'));    
        break;
}

Problem Statement:

I am wondering what changes I should make in the SQL Query above so that it sorts everything on the basis of customer_name only but sorting should follow the logic as mentioned below:

let arr = [
  '1 Hello',
  '2 Hello',
  '3 Hello',
  '4 Hello',
  ';1',
  'z',
  '%1',
  '110 Hello',
  '100 Hello',
  'a',
  'Z',
  '00',
  '21 Hello',
  '9  Hello',
  '13 Hello',
  '10000 Hello',
  '0 Hello',
  'A'
  ];


arr.sort( (a, b) => {
  return a.localeCompare(b, 'en', {
    numeric: true
  })
} ).forEach( ml => { console.log(ml) });

The above Javascript is printing the following o/p:

;1
%1
00
0 Hello
1 Hello
2 Hello
3 Hello
4 Hello
9  Hello
13 Hello
21 Hello
100 Hello
110 Hello
10000 Hello
a
A
z
Z
=> undefined

So I want to sort all the data on customer_name in my above php file but in Lexicographical order just like my above javascript is doing.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
    • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
    • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
    • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
    • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
    • ¥15 python爬取bilibili校园招聘网站
    • ¥30 求解达问题(有红包)
    • ¥15 请解包一个pak文件
    • ¥15 不同系统编译兼容问题
    • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?