Sort an array by a child array's value

Posted by Evan on Stack Overflow See other posts from Stack Overflow or by Evan
Published on 2010-04-20T06:03:58Z Indexed on 2010/04/20 6:13 UTC
Read the original article Hit count: 408

Filed under:
|
|

I have an array composed of arrays. I want to sort the parent array by a property of the child arrays. Here's an example

array(2) {
  [0]=>
  array(3) {
    [0]=>
    string(6) "105945"
    [1]=>
    string(10) "First name"
    [2]=>
    float(0.080878465391)
  }
  [1]=>
  array(3) {
    [0]=>
    string(6) "109145"
    [1]=>
    string(11) "Second name"
    [2]=>
    float(0.0504154818384)
}

I would like to sort the parent array by [2] ascending in the child arrays, so in this case the result would be the child arrays reversed (.05, 08). Is this possible using any of the numerous PHP sort functions?

© Stack Overflow or respective owner

Related posts about php

Related posts about sorting