Jump to content

[SOLVED] need help with complicated switch statements


dsaba

Recommended Posts

Hey I need to make if/else statements or switch statements that

If this ONE THING IS TRUE

then ALL THESE MULTIPLE ITEMS ARE TRUE

 

I know how to make many if/else statements when

If this ONE THING IS TRUE

Then THIS ONE THING IS TRUE

 

the problem is I dont know the syntax or are confused on how to make many things true if one statement is true, basically i'm creating many variables if one statement is true, instead of just creating 1 variable if one statement is true

 

i'm looking at creating at least 5 variables depending on one statement to be true

if this can be done or the syntax in doing it is where I need help

 

sample code

//put translations for ifsubtitle
$svideosubmitterlang = he;
$svideoifsubtitle = (unknown)(could be Ken or Lo);

switch ($svideoifsubtitle)
{
  case "Ken" : 
     $ifsubtitle_en = Yes & $ifsubtitle_es = Si; //here i'm just making 2 variables but i want to make 5 here
     break;
  case "Lo" : 
     $ifsubtitle_en = No & $ifsubtitle_es = No;
     break;
  default : 
     echo "unable to determine if svideosubtitle is Ken or Lo adn then make the right translation variables";
     break;
}

 

<?php

switch ($svideoifsubtitle)
{
  case "Ken" : 
     $ifsubtitle_en = Yes 
     $ifsubtitle_es = Si;
     $var1 = TRUE;
     $var2 = TRUE;

     break;
  case "Lo" : 
     $ifsubtitle_en = No 
     $ifsubtitle_es = No;
     $var1 = FALSE;

     break;
  default : 
     echo "unable to determine if svideosubtitle is Ken or Lo adn then make the right translation variables";
     break;
}

?>

The & operator is only something that's used in the conditions in if-statements. Outside of that it doesn't do anything. And as Pocobueno said, if a switch statement evaluates to true, it will continue execution until a break is reached.

You are wrong. Although dsaba did use the & wrongly.

First, && means "and" in conditionals. It's not & that means "and" with logical expressions, but &&.

Second, & does have a meaning- it is the bitwise operator "and".

 

Orio.

oh since this post is already made i have some more question about if/else or switch statements

 

can you put if and else statements inside of each other

can you do this with switch statements too?

 

for example IF this thing is true

               THEN execute this if/else statements

 

and can you do this with switch statements too? put them inside of each other

if so could you give me example of the syntax of this for switch and if/else statements

what kind of brackets to enclose..etc...

 

this isn't stuff they normally address in beginners tutorials

Yes you can.

First, my suggestion, read in the manual about the control structures.

 

Example for if inside and if:

<?php

if($var1 == 1)
{
if($var2 == 2)
	echo "Var1 is 1 and Var2 is 2!";
else
	echo "Var1 is 1 and Var2 is not 2!";
}
else
echo "Var1 is not 1!";

?>

 

Orio.

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.