dsaba Posted February 25, 2007 Share Posted February 25, 2007 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; } Link to comment https://forums.phpfreaks.com/topic/40041-solved-need-help-with-complicated-switch-statements/ Share on other sites More sharing options...
Orio Posted February 25, 2007 Share Posted February 25, 2007 You can have more than one line in each case: <?php switch ($svideoifsubtitle) { case "Ken" : $ifsubtitle_en = Yes; $ifsubtitle_es = Si; break; //etc' } ?> Orio. Link to comment https://forums.phpfreaks.com/topic/40041-solved-need-help-with-complicated-switch-statements/#findComment-193648 Share on other sites More sharing options...
pocobueno1388 Posted February 25, 2007 Share Posted February 25, 2007 <?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; } ?> Link to comment https://forums.phpfreaks.com/topic/40041-solved-need-help-with-complicated-switch-statements/#findComment-193650 Share on other sites More sharing options...
Scriptor Posted February 25, 2007 Share Posted February 25, 2007 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. Link to comment https://forums.phpfreaks.com/topic/40041-solved-need-help-with-complicated-switch-statements/#findComment-193651 Share on other sites More sharing options...
dsaba Posted February 25, 2007 Author Share Posted February 25, 2007 AWESOME! just what i needed to know, thanks a lot guys :) :) :) :) :) Link to comment https://forums.phpfreaks.com/topic/40041-solved-need-help-with-complicated-switch-statements/#findComment-193652 Share on other sites More sharing options...
Orio Posted February 25, 2007 Share Posted February 25, 2007 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. Link to comment https://forums.phpfreaks.com/topic/40041-solved-need-help-with-complicated-switch-statements/#findComment-193653 Share on other sites More sharing options...
dsaba Posted February 25, 2007 Author Share Posted February 25, 2007 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 Link to comment https://forums.phpfreaks.com/topic/40041-solved-need-help-with-complicated-switch-statements/#findComment-193655 Share on other sites More sharing options...
papaface Posted February 25, 2007 Share Posted February 25, 2007 The answer to your questions is Yes e.g if (isset($_POST['submit'])) { if ($_POST['text'] == "hello") { echo "Hello"; } } else { echo "fill in this form"; //form } Link to comment https://forums.phpfreaks.com/topic/40041-solved-need-help-with-complicated-switch-statements/#findComment-193658 Share on other sites More sharing options...
Orio Posted February 25, 2007 Share Posted February 25, 2007 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. Link to comment https://forums.phpfreaks.com/topic/40041-solved-need-help-with-complicated-switch-statements/#findComment-193659 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.