ultrus Posted July 27, 2011 Share Posted July 27, 2011 Hi, I've done this before a few times but lose it every time. I have an array that looks like this: <?php $array = array( array('nid'=>17,'title'=>'Here is the last title','sortid'=>7), array('nid'=>18,'title'=>'Here is the first title','sortid'=>1), array('nid'=>19,'title'=>'Here is the middle title','sortid'=>5), ); ?> How do I sort this array by the sortid field ascending so that the titles read: Here is the first title Here is the middle title Here is the last title Thanks for your feedback in advance Quote Link to comment https://forums.phpfreaks.com/topic/243016-troubles-sorting-a-complex-array/ Share on other sites More sharing options...
AyKay47 Posted July 27, 2011 Share Posted July 27, 2011 look into using array_multisort Quote Link to comment https://forums.phpfreaks.com/topic/243016-troubles-sorting-a-complex-array/#findComment-1248183 Share on other sites More sharing options...
Pikachu2000 Posted July 27, 2011 Share Posted July 27, 2011 This data isn't coming from a DB query result by chance, is it? Quote Link to comment https://forums.phpfreaks.com/topic/243016-troubles-sorting-a-complex-array/#findComment-1248184 Share on other sites More sharing options...
ultrus Posted July 27, 2011 Author Share Posted July 27, 2011 AyKay47, I'm re-brushing up on array_multisort() now. Pikachu2000, Nah, this is produced from a Drupal template file. No direct db query at this time. Quote Link to comment https://forums.phpfreaks.com/topic/243016-troubles-sorting-a-complex-array/#findComment-1248199 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.