mcdof001 Posted September 29, 2007 Share Posted September 29, 2007 Hi, I would like to say this:- if variable 1 is either 2 less, 1 less, the same, 1 more or 2 more than variable 2 do an action. can anybody help me on how i would code that! Link to comment https://forums.phpfreaks.com/topic/71148-solved-operators/ Share on other sites More sharing options...
dingus Posted September 29, 2007 Share Posted September 29, 2007 im not shore if i understand you but is this what you are looking for? if ($veriable < $veriable + 2 && $veriable > $veriable - 2){ // do somthing funky } if not can you clean up what you said so it makes a little more sence Link to comment https://forums.phpfreaks.com/topic/71148-solved-operators/#findComment-357807 Share on other sites More sharing options...
hvle Posted September 29, 2007 Share Posted September 29, 2007 Do you mean to say if (var1 >= (var2 -2) && var1 <= (var2 + 2)) ? sound tough to me. Link to comment https://forums.phpfreaks.com/topic/71148-solved-operators/#findComment-357810 Share on other sites More sharing options...
Cagecrawler Posted September 29, 2007 Share Posted September 29, 2007 <?php if(abs($var1-$var2) <= 2){ //Do stuff } Link to comment https://forums.phpfreaks.com/topic/71148-solved-operators/#findComment-357811 Share on other sites More sharing options...
mcdof001 Posted September 29, 2007 Author Share Posted September 29, 2007 sorry. its so hard to explain. if variable 1 is i inbetween the range or two more or two less do an action. i have done it the long way round. here is what i ment... if ($a == $a1) { //the same action } elseif ($a == $a1 + 1) { //the same action } elseif ($a == $a1 + 2) { //the same action } elseif ($a == $a1 - 1) { //the same action } elseif ($a == $a1 - 2) { //the same action } Link to comment https://forums.phpfreaks.com/topic/71148-solved-operators/#findComment-357822 Share on other sites More sharing options...
mcdof001 Posted September 29, 2007 Author Share Posted September 29, 2007 thanks everyone for your help! Link to comment https://forums.phpfreaks.com/topic/71148-solved-operators/#findComment-357824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.