SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    stirling
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function to get the lowest value

    Hi, i am looking for i function that accepts one value at a time checks if the first value is less than 28, if true keeps it, gets the second value, checks it if it is the lowest so far and so on. the function will be called passing the value to be checked each time. Anybody seen any similar functions or tutorials around??
    thanks, dh

  2. #2
    With More ! for your $ maxor's Avatar
    Join Date
    Feb 2004
    Location
    Scottsdale, Arizona
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How are you getting the values? Are they in an array or something?

  3. #3
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if there's one in PHP (if there is I couldn't find it), so I rolled my own:
    PHP Code:
    function getLower$val1$val2 )
    {
        return (
    $val1 $val2) ? $val1 $val2;
    }

    // usage:
    $num1 $_GET['a_number'];

    $low_num getLower$num128 );
    // etc. 
    (edit: error in code; added sample usage)

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    stirling
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry should have included more details. I have so far used a function to work out 5 handicaps. What i need to do is find out which of these is the lowest and output that. I was thinking a function could hold the highest possible handicap(28) from the start and compare each score in turn to see if it was lower. I f it is then overwrite 28 with it and compare the next score to it and eventually have stored the lowest score.

    print calculate ($score1, $par1, $slope1);
    print calculate ($score2, $par2, $slope2);
    print calculate ($score3, $par3, $slope3);
    print calculate ($score4, $par4, $slope4);
    print calculate ($score5, $par5, $slope5);

    function calculate($score, $par, $slope){
    $scoreDifference = $score - $par;
    $overallSlope = 113 / $slope;
    $scoreDifferential = $scoreDifference * $overallSlope;
    $handicap = $scoreDifferential * 0.96;
    print getLowest($handicap;
    return $handicap;
    }

  5. #5
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see what you are trying to do now. You may want to take advantage of the array sorting functions in php: (slight adjustment to code needed)
    PHP Code:
    $handicap1 calculate ($score1$par1$slope1);
    $handicap2 calculate ($score2$par2$slope2);
    $handicap3 calculate ($score3$par3$slope3);
    $handicap4 calculate ($score4$par4$slope4);
    $handicap5 calculate ($score5$par5$slope5);

    # turn the above into an array for sorting
    $handicaps = array( $handicap1$handicap2$handicap3$handicap4$handicap5 );
    sort$handicapsSORT_NUMERIC );

    # this is the value you wanted
    $lowest_handicap $handicaps[0];

    # removed print thing from function
    function calculate($score$par$slope) {
      
    $scoreDifference $score $par;
      
    $overallSlope 113 $slope;
      
    $scoreDifferential $scoreDifference $overallSlope;
      
    $handicap $scoreDifferential 0.96;
      return 
    $handicap;


  6. #6
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would min work at all for you?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  7. #7
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vinyl-junkie
    Would min work at all for you?
    Absolutely - I've been re-inventing the wheel all along

    Thanks Vinyl.

  8. #8
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm glad I could help.

    Here are a couple of other functions that might be useful for your application as well.

    floor - to round fractions down

    ceil - to round fractions up

    Pretty cool, huh?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •