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 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题