2
Array
(
[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.

4
  • Define: "without calling any external function" Commented Jan 17, 2011 at 6:15
  • have you looked at array_multisort? Commented Jan 17, 2011 at 6:16
  • m.d. for multidimensional and acc. for according are not standard shortcuts as far as I know Commented Jan 17, 2011 at 6:17
  • 1
    Improving the efficiency of what? I can't see any code. Commented Jan 17, 2011 at 6:17

1 Answer 1

3

I doubt there is something faster than array_multisort() https://www.php.net/array_multisort

UPDATE:

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:

http://php.net/manual/en/function.usort.php

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

usort($arr, 'cmp');
Sign up to request clarification or add additional context in comments.

1 Comment

Please give an example how to use array_multisort in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.