ayush ayush - 3 years ago 149
PHP Question

Fastest way of sorting multidimensional arrays in php

[0] => Array
[t] => 81881
[b] => 99494
[1] => Array

I have a multidimensional array like above.The entries in this array would be ranging upto 20k. I want to sort this array acc. to "t" index without calling any external function. Any suggestions for improving the efficiency.

Answer Source

I doubt there is something faster than array_multisort() http://us2.php.net/array_multisort


Finding out now, that data is not really multidimensional (it's just a key that's hidden as a val of item in array). It would be probably easier to use something like:


function cmp($a, $b)
    return $a['t']<=>$b['t'];

usort($arr, 'cmp');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download