SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: function to get the lowest value
-
Nov 25, 2004, 17:05 #1
- 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
-
Nov 25, 2004, 17:17 #2
- 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?
-
Nov 25, 2004, 17:26 #3
- 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( $num1, 28 );
// etc.
-
Nov 30, 2004, 04:54 #4
- 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;
}
-
Nov 30, 2004, 16:39 #5
- 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( $handicaps, SORT_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;
}
-
Nov 30, 2004, 20:36 #6
- 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
-
Nov 30, 2004, 20:41 #7
- Join Date
- Aug 2003
- Location
- Melbourne, Australia
- Posts
- 454
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by vinyl-junkie
Thanks Vinyl.
-
Nov 30, 2004, 20:50 #8
- Join Date
- Dec 2003
- Location
- Federal Way, Washington (USA)
- Posts
- 1,524
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
Showcase your music collection on the Web
Bookmarks