dsaba Posted May 20, 2007 Share Posted May 20, 2007 if you have a series of elseif statements, if one elseif executes and the others are also true will they also execute? or will the statement stop when it finds the first if or elseif to be true? example: if bla bla elseif bla bla elseif bla bla elseif bla bla Quote Link to comment https://forums.phpfreaks.com/topic/52182-solved-question-about-elseif-statements/ Share on other sites More sharing options...
cgishack Posted May 20, 2007 Share Posted May 20, 2007 it will just find 1 try it <html> <head> <title>Sample</title> </head> <body> <? $char1 = "A"; $char2 = "B"; $char3 = "C"; $char4 = "D"; if ($char1 == "B") { print "char 1"; } else if ($char2 == "B") { print "char 2"; } else if ($char3 = "C") { print "char 3"; } else { print "none"; } ?> </body> </html> Drew Quote Link to comment https://forums.phpfreaks.com/topic/52182-solved-question-about-elseif-statements/#findComment-257350 Share on other sites More sharing options...
JasonLewis Posted May 20, 2007 Share Posted May 20, 2007 correct me if i am wrong but it will only continue if the statement is false. so: $a = 1; $b = 4; if($a == 1){ echo "A is 1<br>"; }elseif($a == 2){ echo "A is 2<br>"; }elseif($b == 4){ echo "B is 4"; } above would only echo A is 1. Quote Link to comment https://forums.phpfreaks.com/topic/52182-solved-question-about-elseif-statements/#findComment-257351 Share on other sites More sharing options...
quickstopman Posted May 20, 2007 Share Posted May 20, 2007 i think it would have to be like this <? if (BLAH) { } else if (BLAH) { else if (BLAH) { } else if (BLAH) { }else if (BLAH) { } } else if (BLAH) { } ?> you would but a bunch of different else if statements in side of one of the else if state ments i probly didn't show it very well but u should get what i mean Quote Link to comment https://forums.phpfreaks.com/topic/52182-solved-question-about-elseif-statements/#findComment-257352 Share on other sites More sharing options...
dsaba Posted May 20, 2007 Author Share Posted May 20, 2007 thats what I thought -thanks topic solved Quote Link to comment https://forums.phpfreaks.com/topic/52182-solved-question-about-elseif-statements/#findComment-257355 Share on other sites More sharing options...
dsaba Posted May 20, 2007 Author Share Posted May 20, 2007 -off topic how do you highlight the php code without putting it in code tags??? Quote Link to comment https://forums.phpfreaks.com/topic/52182-solved-question-about-elseif-statements/#findComment-257356 Share on other sites More sharing options...
JasonLewis Posted May 20, 2007 Share Posted May 20, 2007 you use [ php ] [ / php ] minus the spaces. Quote Link to comment https://forums.phpfreaks.com/topic/52182-solved-question-about-elseif-statements/#findComment-257358 Share on other sites More sharing options...
dsaba Posted May 20, 2007 Author Share Posted May 20, 2007 aha, they should add that to the thread editor, because i've always wanted to know how to do that, i keep seeing others pull that one Quote Link to comment https://forums.phpfreaks.com/topic/52182-solved-question-about-elseif-statements/#findComment-257359 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.