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? 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 ?> Link to comment https://forums.phpfreaks.com/topic/87612-variable-comparison/#findComment-449569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.