Jump to content

conditional commands


formula455

Recommended Posts

Hi.. if i remember right this code i'm about to show used to work. I don't know if i'm doing something wrong... or if my webserver is just not supporting it.

 

<? if($var == (("condition1") || ("condition2"))) { echo "fubar"; } ?>

 

basically if $var is either condition1 or condition2 it would echo fubar. what's happening is on my webserver it's echoing fubar reguardless of what either condition is. if i make each condition seperate it works.. like so....

 

<? if($var == "condition1" OR $var == "condition2") { echo "fubar"; } ?>

 

i could technically do it this way... if theres going to be alot of conditions and i would prefer to use the first route.

 

so yah if theres something i'm doing wrong please gimmi the heads up otherwise i guess its my webserver not allowing the conditional commands

Link to comment
https://forums.phpfreaks.com/topic/109533-conditional-commands/
Share on other sites

Hey mate.

 

I am no expert but in the first statement I think you are telling php to check :

 

if($var == condition1) or if condition2 is true. It is not comparing var to condition 2. And I guess condition 2 will always be true since it is not getting compared to something , so the whole expression will always be true so .. it will always echo"fubar";

 

Ofcourse I might misunderstand something but I hope I helped.

Link to comment
https://forums.phpfreaks.com/topic/109533-conditional-commands/#findComment-561875
Share on other sites

well you could use a switch statement if you got too many checks to make:

 


switch($var)
{
     case condition1:
     case condition2:
     case condition3:
     case condition4:
     .....................
      case conditionn:
          echo"fubar";
            break;
     default:
        echo"not fubar ";
          break;
}

Link to comment
https://forums.phpfreaks.com/topic/109533-conditional-commands/#findComment-561889
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.