开发者

Sorting a multi-dimensional array by the size of its sub-arrays

开发者 https://www.devze.com 2023-01-24 06:24 出处:网络
Suppose I have an array of arrays, and I want to sort the big array by the # of in开发者_如何学运维dexes in the sub-arrays, what would be the most efficient way to do that?

Suppose I have an array of arrays, and I want to sort the big array by the # of in开发者_如何学运维dexes 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));'));
0

精彩评论

暂无评论...
验证码 换一张
取 消