由它的子阵列的大小排序的多维阵列 [英] Sorting a multi-dimensional array by the size of its sub-arrays
本文介绍了由它的子阵列的大小排序的多维阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个数组的数组,我想通过在子阵列索引的#大数组进行排序,这将是做到这一点的最有效的方法是什么?
这是我迄今为止
$排序顺序= array_map('数',$ largearray);
在array_multisort($排序顺序,$ largearray);
什么比这更好的?
解决方案
usort($阵列,create_function('$ A,$ B','回报bccomp(计数($ A) ,计数($ b));'));
Suppose I have an array of arrays, and I want to sort the big array by the # of indexes in the sub-arrays, what would be the most efficient way to do that?
This is what I have so far
$sortorder = array_map('count', $largearray);
array_multisort($sortorder, $largearray);
Anything better than this?
解决方案
usort($array, create_function('$a, $b', 'return bccomp(count($a), count($b));'));
这篇关于由它的子阵列的大小排序的多维阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文