| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| NamePros Regular | Finding highest value in variables I have 3 variables I would like to check the value of each and select the one that is the highest. They must be atleast .05 or higher I was thinking something like if ($var1 <= .049 || $var2 <= .049 || $var3 <= .049 ) { echo 'value to low'; } else { this is where Im confused, how to select the variable with the highest value } any help is appreciated. Thanks Turk
__________________ I'm a member of WebMaster Haven.com New Web Master Forum. |
| |
| | #2 (permalink) |
| Senior Member | well simply, u cud to this: else if($var1 > $var2 || $var1 > $var3) { echo('Var 1 is the highest.'); } else if($var2 > $var1 || $var2 > $var3) { echo('Var 2 is the highest.'); } else if($var3 > $var2 || $var3 > $var1) { echo('Var 3 is the highest.'); } that wud go after ur part (where the else in ur statement where u got lost is)
__________________ Hacksar.com - Your source for random computer tips and tricks! MySiteMemberships.com - Keep track of your site registration information! Like my post? Rep is appreciated! |
| |
| | #3 (permalink) |
| NamePros Regular | A couple ways off the top of my head: 1) Put the values into an array and use rsort() ex: $numbers = array(34,65,23); $sortnumbers = rsort($numbers,SORT_NUMERIC); $highestnumber = $sortnumbers[0]; 2) Process of elimination: ex: if ($a > $b) { $firstroundwinner = $a; }else{ $firstroundwinner = $b; } if ($firstroundwinner > $c) { $highestnumber = $firstroundwinner; }else{ $highestnumber = $c; } |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Your highest value domain sold? | ridesign1 | Domain Name Discussion | 20 | 12-31-2005 02:19 PM |
| DownloadSex.us - Taking Offers - $25 is the Current highest Only 1 1/2 days to go. | Miloj | Adult Domains For Sale | 2 | 04-30-2005 04:56 PM |
| String and variables | lovelinuxlove | Programming | 2 | 10-31-2004 04:26 AM |
| How I fill javascript array with php variables? | wiedzim | CODE | 0 | 03-31-2004 02:45 AM |