Re: Determine variable with the lowest value?
| From: | BOOT | Date: | Thu, 14 Oct 2004 15:52:20 +0000 |
| Subject: | Re: Determine variable with the lowest value? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-199487@lists.php.net to get a copy of this message | ||
OK thanks but I guess I didn't explain what I am trying to do properly.
I need to be able to identify the variable name as well as pick the variable
with the lowest value.
Something like this:
Whose turn is it to take out the garbage?
Mike has done it 3 times
Bob has done it 2 times
Jane has done it 5 times
etc...
Therefore its Bob's turn.....
"Eric McGrane" <emcgrane@anacomp.com> wrote in message
news:20041014133835.32752.qmail@pb1.pair.com...
> 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!