On Wed, 2004-06-02 at 12:59, John Nichel wrote: > Okay, I know someone is going to shoot me for asking such a dumb > question, but I just can't seem to find the answer anywhere. I have a > multidimensional array which I would like to sort on the value of one of > the keys... > > Array > ( > [0] => Array > ( > [foo] => blah > [bar] => blah > [sort] => 5 > ) > [1] => Array > ( > [foo] => blah > [bar] => blah > [sort] => 2 > ) > [2] => Array > ( > [foo] => blah > [bar] => blah > [sort] => 4 > ) > [3] => Array > ( > [foo] => blah > [bar] => blah > [sort] => 3 > ) > [4] => Array > ( > [foo] => blah > [bar] => blah > [sort] => 1 > ) > ) > > What I would like to do is sort this on the value of 'sort' in each > sub-array. What am I missing???? TIA
usort( $theAboveArray, 'mySortHandler' ); function mySortHandler( $v1, $v2 ) { if( $v1['sort'] > $v2['sort'] ) { return 1; } else if( $v1['sort'] < $v2['sort'] ) { return -1; } return 0; } Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php