Combining If and Include Statements

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
divconf
Forum Newbie
Posts: 1
Joined: Fri Jun 12, 2009 2:17 pm

Combining If and Include Statements

Post 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!!
Last edited by Benjamin on Fri Jun 12, 2009 5:40 pm, edited 1 time in total.
Reason: Added [code=php] tags.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Combining If and Include Statements

Post by Mark Baker »

othercode.php would not be parsed if $variable was false
thk2551985
Forum Newbie
Posts: 2
Joined: Mon Jul 21, 2008 7:01 am

Re: Combining If and Include Statements

Post 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 :)
Last edited by Benjamin on Fri Jun 12, 2009 5:41 pm, edited 1 time in total.
Reason: Added [code=php] tags.
Post Reply