PHP按子值对数组进行排序 [英] php sort array by sub-value
本文介绍了PHP按子值对数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的数组,我认为我应该使用usort,但我不知道如何使它工作.
here is my array, I think i should be using usort but i have no idea how to get that working.
Array
(
[javascript] => Array
(
[core] => Array
(
[0] => Array
(
[file] => /path/to/file.js
[weight] => 0
)
[1] => Array
(
[file] => /path/to/file2.js
[weight] => 1
)
)
)
)
我想按权重值对核心索引进行排序,其他文件和权重也将添加并排序.
I would like to sort the index of core by the weight value, other files and weights will be added and sorted after also.
推荐答案
usort($array['javascript']['core'], function($a, $b) {
return $a['weight'] - $b['weight'];
});
这篇关于PHP按子值对数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文