How to sort a multidimensional array by a certain key?

前端 未结 5 1608
误落风尘
误落风尘 2020-11-27 08:15

This should be really simple, but what is the way to go on this. I want to sort an multidimensional array by a key, like this:

Array (
[0] => Array
    (         


        
5条回答
  •  無奈伤痛
    2020-11-27 08:41

    Try this

    function cmp_by_status($a, $b)
    {
        if ($a['status'] == $b['status']) {
            return 0;
        }
        return ($a['status'] < $b['status') ? -1 : 1;
    }
    
    usort($data_array, "cmp_by_status");
    

提交回复
热议问题