数组排序而无需重写关键 [英] Sort an array without rewriting a key
本文介绍了数组排序而无需重写关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数组,看起来像这样:
I have an array which looks like this:
$arr = ( [0]=>Int(2)
[1]=>Array( ....)
[2]=>Array( ....)
[3]=>Array( ....))
我已经使用usort对它进行排序:
I have used usort to sort it:
usort($arr,function($a, $b) {
if($a['prop'] == $b['prop']) return 0;
return ($a['prop'] < $b['prop']) ? 1 : -1;
});
我的问题是关键[0]改写用数组元素。不要误会我的意思......它的猜想。我怎么可以在$ ARR数组没有改写键排序[0]?
My problem is that the key [0] is rewritten with an Array element. Don't get me wrong...it's suppose to. How could i sort the $arr array without rewrite the key [0] ?
推荐答案
只需使用uasort()
just use uasort()
http://php.net/manual/en/function.uasort.php
这篇关于数组排序而无需重写关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文