Page 1 of 1

Combining If and Include Statements

Posted: Fri Jun 12, 2009 2:21 pm
by divconf
I am trying to find ways to make my code more efficient. One idea I had was to use If statements followed by including code if the statement is true. However, I wondered whether the PHP code of an include statement is parsed whether or not the If statement that precedes it is true.

For example:

Code: Select all

If ($variable == true) {
          include othercode.php;
}
In this event, would othercode.php be parsed if $variable is false?

Thanks!!

Re: Combining If and Include Statements

Posted: Fri Jun 12, 2009 2:30 pm
by Mark Baker
othercode.php would not be parsed if $variable was false

Re: Combining If and Include Statements

Posted: Fri Jun 12, 2009 2:31 pm
by thk2551985
Hi

Code: Select all

If ($variable == true) {
include othercode.php;
}
In this example, the parser only checks whether the $variable is true or not. If it is true then only it executes othercode.php by including it. Otherwise it skips to execute the statement and the parser goes to next statement after if statement.

Thanks :)