我有一个如下所述的数组
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
)
)
Run Code Online (Sandbox Code Playgroud)
现在,订单是:额外,办公用品,硬件零件
我想按顺序排序主数组,它是按顺序排列的内部数组的total_sales
所以订单将是:办公用品,附加产品,硬件零件
任何帮助家伙
dec*_*eze 16
PHP 5.3:
usort($array, function ($a, $b) { return $b['total_sales'] - $a['total_sales']; });
Run Code Online (Sandbox Code Playgroud)
PHP 5.2-:
usort($array, create_function('$a,$b', 'return $b["total_sales"] - $a["total_sales"];'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5856 次 |
| 最近记录: |