jrobles Posted April 15, 2010 Share Posted April 15, 2010 I'm trying to find the 2 lowest values in an array. I know how to grab the lowest value min() but i cannot seem to figure out the syntax to find the 2, 3 or 4 lowest values. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/198653-min/ Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 min works with arrays too. Link to comment https://forums.phpfreaks.com/topic/198653-min/#findComment-1042465 Share on other sites More sharing options...
jrobles Posted April 15, 2010 Author Share Posted April 15, 2010 min works with arrays too. I know, min($array); works like a champ but only gives me the single lowest value in the array. I need the two lowest values in the array Link to comment https://forums.phpfreaks.com/topic/198653-min/#findComment-1042477 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 Oh sorry. My mistake. Try sort. Link to comment https://forums.phpfreaks.com/topic/198653-min/#findComment-1042480 Share on other sites More sharing options...
teamatomic Posted April 15, 2010 Share Posted April 15, 2010 If you want two values the quickest way is probably to natsort it then just grab array[0] and array[1]. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/198653-min/#findComment-1042539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.