php 二维数组排序

php 二维数组排序

<?php

$array = [
    ['key1' => 10, 'key2' => 'wang'],
    ['key1' => 2, 'key2' => 'WANG'],
    ['key1' => 30, 'key2' => 'king'],
    ['key1' => 34, 'key2' => 'KING'],
    ['key1' => 301, 'key2' => 'kING'],
    ['key1' => 20, 'key2' => 'King'],
    ['key1' => 400, 'key2' => 'Wang'],
    ['key1' => 400, 'key2' => 'ABCDEFG'],
    ['key1' => 400, 'key2' => 'ABCDEFg'],
    ['key1' => 400, 'key2' => 'AbcDEFG'],
    ['key1' => 400, 'key2' => 'AbcdEFG'],
    ['key1' => 400, 'key2' => 'Bacdefg'],
];
¬
function asc_sort($a, $b) {
    if($a['key1'] > $b['key1']) {
        return true;¬
    } else if($a['key1'] < $b['key1']) {
        return false;
    } else {
        return 0;
    }
}



function asc_name_sort($a, $b) {
    return strcmp($a['key2'], $b['key2']);
}


//usort($array, 'asc_sort');
usort($array, 'asc_name_sort');

var_dump($array);

 

打赏 赞(1)
微信
支付宝
微信二维码图片

微信扫描二维码打赏

支付宝二维码图片

支付宝扫描二维码打赏

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据