![]() Equipping Your Church to Communicate Effectively | ![]() Go PRO - Enjoy PRO Benefits! |
![]() | ![]() |
| |||||||
| Website Coding Discussions PHP, MySQL, Java, Javascript, ASP, etc. |
![]() |
| | Thread Tools | Search this Thread | Rate Thread | Display Modes |
| |||
| How to continue PHP source code to another line in editor Thanks for reading, I hope this could be a help for someone else as well in the future as googling for an hour did not result more than one relative answer. Usually Google rocks, but this one was hard with the search words.... ![]() What are the options to deal with a rather long if() statement? I think I found one working solution after littlebit of testing, but as it's part of security script I would not like to rely just solely on my own testing. Here's the example of long statement: Code: $a=1;
$b=2;
$c=3;
$d=4;
if($a==1 && $b==2 && $c==3 && $d==4) {
print "Pass";
}
else print "Fail"; Code: $a=1;
$b=2;
$c=3;
$d=4;
if($a==1 &&
$b==2 &&
$c==3 &&
$d==4) {
print "Pass";
}
else print "Fail"; ![]() I know on other languages I could use an underscore "_" or forward slash "/" or such and I was wondering if PHP comes with any of those? Also I figured this would be a good time to use an alternative to the if() statement. Maybe the switch/case would work better on this, but please still answer the original question. Thanks in advance! Temex |
| ||||
| Argh!!!!! I just wrote a really nice long message about this and some other things for you, and the focus went out of this input area and I hit backspace, which took me to the previous page so I lost it all! Short answer now, will elaborate more later: To PHP, both examples you have look the exact same, all whitespace (spaces, tabs, newlines), get treated the exact same outside of quoting. Also something i elaborated on more in the "lost" message was a note that when you do multiple conditions, PHP will stop evaluating as soon as it knows the outcome. Basic logic rules, FALSE && (and) anything else will always be false, so as soon as it gets a false condition AND'd with anything else, it stop evaluating. Same for OR statements, TRUE || (or) anything else will always be true, so once it gets to that it will stop. Later I'll explain in an article the uses and benefits of knowing this. Have a great day! -Greg |
| |||
| Hehe..Greg, I'm posting this second time as well, but the funny thing is my original message included the PS for you (see below). So here it comes.. only 2 seconds later ![]() Thanks Danroth and Greg, Whoops, that was funny you pointed out the space between the function and the condition, I had to go to check my scripts and yes, I do have spaces there so I'm allright ![]() Also, I have no problems with boolean and such, but just wanted to double check how breaking single line in PHP would result on the statement as far as parsing goes. I must use it on script dealing with security and definitely want to avoid any nasty surprices. In my case more practical could be to use switch/case, but the whole hassle is so long and complicated that I must rewrite it on better time. Thanks for your both and I hope this helps someone else too Googling to this page. Some answers are just hard to Google due to search words it involves such as PHP, another line, source code, multiline,... try it for yourself if you're boored enough ![]() Temex PS: Greg: After filling textbox like this one, I 98% of time just hit CTRL+A and then CTRL+C ...takes about 0.2 seconds but could save fortune! (And CTRL+Z in case something wen't wrong already.) Hope that saves your next mess ![]() |