Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

PHP Variables Great Than Less Than

If I have a variable that has a lot of comma separated numbers.
$var = '594,458,458,458,40,40,488,488,200,40,40,80,120,200,514,5';

And I have two other variables that I want to compare it against
$var_a = "475";
$var_b = "450";

And I want to write the following;
if($var contains a number that is Less than or equal to <= $var_a AND contains a number that is greater than or equal to $var_b) {
 $my_new_var = "TRUE";
}
I'm not surre how to write that
ASKER CERTIFIED SOLUTION
Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robert Granlund

ASKER

I have the following but I don't think it is correct.
It is always echoing "HELLO"
$wave = $row['wavelength'];
   			$wave = explode(', ', $wave);
   			echo'<br />'.$wave[0].'<br />'.$wave[1].'<br />';

   			$a = false;
   			$b = false; 

   			if($wave[0] <= $wave_max) $a = true; 
   			if($wave[1] >= $wave_min) $b = true; 
   			
   			if($a && $b) $wavelength = true;
   			
   			if($wavelength) {
   				echo '<h1>HELLO</h1>';
   			}		

Open in new window

Never mind my last comment.  That works well.  Thanks.