Re: Determine variable with the lowest value?

From: Date: Thu, 14 Oct 2004 13:38:03 +0000
Subject: Re: Determine variable with the lowest value?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-199476@lists.php.net to get a copy of this message
Why use the min function? Just sort the array and then grab the first element in the sorted array. No random picking required. E "Paul" <pfine@of-law.com> wrote in message news:20041014032015.69904.qmail@pb1.pair.com... > Thanks guys. Yes I figured using an array and the MIN function would be a > start. > > Now the random part..... > > > > > "Boot" <pfine@of-law.com> wrote in message > news:20041013221858.60629.qmail@pb1.pair.com... > > Any help with this would be appreciated. > > > > I am trying to come up with something that will find which variable(s) > have > > the lowest value and inidicate which variable this is. In the event that > > variables have an equally low value then it is to randomly pick one of the > > variables and idicate which this is. > > > > I have been able to do this by means of if comparisons but the more I > > variables I add then the more complicated and messy it becomes. There has > to > > be a simpler way. If it makes any difference, the variables could just as > > easily be array elements. > > > > example: > > > > $a = 2 > > $b =2 > > $c= 4 > > $d= 5 > > $e=6 > > $f =7 > > > > the code should determine that $a and $b have the lowest value, and > randomly > > pick one of them. if $a was = 1 instead then it would just pick $a > > > > > > Thanks for any suggestions!

« previous php.general (#199476) next »