aximbigfan Posted September 23, 2008 Share Posted September 23, 2008 Hi, I have a large array of numbers. How can I get a set of the names of 5 of the lowest? For example: bigarray { 0 => 23 1 => 45 2 => 56 3 => 0 4 => 41 5 => 3 6 => 2 7 => 7 } and the set of 5 would b e created in an array like this unpop { 0 => 3 (These are the NAMES of the keys, not the value) 1 => 2 2 => ............... Thanks! Chris Quote Link to comment https://forums.phpfreaks.com/topic/125498-large-array-of-numbers-get-lowest-5/ Share on other sites More sharing options...
.josh Posted September 23, 2008 Share Posted September 23, 2008 use sort() or rsort() ... or am I not understanding you? Quote Link to comment https://forums.phpfreaks.com/topic/125498-large-array-of-numbers-get-lowest-5/#findComment-648799 Share on other sites More sharing options...
F1Fan Posted September 23, 2008 Share Posted September 23, 2008 I agree. Use rsort() and just grab the first X number of elements. Quote Link to comment https://forums.phpfreaks.com/topic/125498-large-array-of-numbers-get-lowest-5/#findComment-648803 Share on other sites More sharing options...
aximbigfan Posted September 23, 2008 Author Share Posted September 23, 2008 Huh, well that works too. Didn't know there was a function to do that, and didn't know how to word the search for one sorry... Chris Quote Link to comment https://forums.phpfreaks.com/topic/125498-large-array-of-numbers-get-lowest-5/#findComment-648815 Share on other sites More sharing options...
.josh Posted September 23, 2008 Share Posted September 23, 2008 btw if you're getting that array from a db query just do it in the query: SELECT blah FROM table ORDER BY blah LIMIT 5 Quote Link to comment https://forums.phpfreaks.com/topic/125498-large-array-of-numbers-get-lowest-5/#findComment-648837 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.