Gibbs Posted October 27, 2007 Share Posted October 27, 2007 I'm trying to find the two largest values in an array. The max function is great but I'm also looking for the second largest number... I can't use any sorting functions as the array name must stay the same. The sort functions I've tried, for example, will rename $array["TEST1"] to $array[0]. Any help appreciated. Thanks. Link to comment https://forums.phpfreaks.com/topic/75011-solved-two-largest-numbers-in-an-array/ Share on other sites More sharing options...
unidox Posted October 27, 2007 Share Posted October 27, 2007 In the query just use ASC/DESC and then pick out the last/first 2 numbers. Link to comment https://forums.phpfreaks.com/topic/75011-solved-two-largest-numbers-in-an-array/#findComment-379303 Share on other sites More sharing options...
Barand Posted October 27, 2007 Share Posted October 27, 2007 use asort() to preserve keys Link to comment https://forums.phpfreaks.com/topic/75011-solved-two-largest-numbers-in-an-array/#findComment-379370 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.