基于内部数组键值的排序数组

问题描述:

我有一个类似于下面提到的数组

I have an array like one mentioned below

Array
(
[6] => Array
    (
        [name] => Extras
        [total_products] => 0
        [total_sales] => 0
        [total_affiliation] => 0
    )

[5] => Array
    (
        [name] => Office Products
        [total_products] => 7
        [total_sales] => 17
        [total_affiliation] => 8
    )

[1] => Array
    (
        [name] => Hardware Parts
        [total_products] => 6
        [total_sales] => 0
        [total_affiliation] => 0
    )

)

现在,订购的是:附件,办公产品,硬件零件

Right now, order is: Extras, Office Products, Hardware Parts

我想按主数组的排序方式,以便按desc顺序按inner-array的total_sales排序

I want to sort main array in such as way that it is order by total_sales of inner-array in desc order

因此订购的将是:办公产品,其他,硬件零件

so order will be: Office Products, Extras, Hardware Parts

任何帮助人员

PHP 5.3:

usort($array, function ($a, $b) { return $b['total_sales'] - $a['total_sales']; });

PHP 5.2-:

usort($array, create_function('$a,$b', 'return $b["total_sales"] - $a["total_sales"];'));