wrathican Posted January 24, 2008 Share Posted January 24, 2008 hi there. my problem is that i have three variables, all of which could be different values (numerical between 1 and 4). i need to compare these vars to each other to see which has the lowest value (1) because i only actually need one value. i have thought about using an if statement something like this if var1 or var2 or var3 are equal to 1 actual value is set to one if var1 or var2 or var3 are equal to 2 actual value is set to one if var1 or var2 or var3 are equal to 3 actual value is set to one if var1 or var2 or var3 are equal to 4 actual value is set to four but how do format the condition? i could do it like this: if(($var1 == 1) || ($var2 == 1) || ($var3 == 1)){ $actualvalue = 1; }else if(......... would that be the best way? or is there an easier way? Quote Link to comment https://forums.phpfreaks.com/topic/87612-variable-comparison/ Share on other sites More sharing options...
irvieto Posted January 26, 2008 Share Posted January 26, 2008 Use "min()" math function Syntax: <?php $var1 = 18; $var2 = 3; $var3 = 153; $var4 = 82; echo min($var1,$var2,$var3,$var4); //Prints 3 ?> Quote Link to comment https://forums.phpfreaks.com/topic/87612-variable-comparison/#findComment-449569 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.