Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditioning incude() 1

Status
Not open for further replies.

smashing

Programmer
Joined
Oct 15, 2002
Messages
170
Location
US
I want to put incude() or require into an if else loop ie:

if ($condition=="a") {
incude 'yes.php';
} else {
incude 'no.php';
}

I understand from php.net that because it's a language construct this isn't possible to do "Variable functions won't work with language constructs" How do I get around this?
 
There is no reason, other than your consistent misspelling of "include" in your example, that your code won't work.

The only stricture is that if you use include() inside a conditional block, you must inclose it in statement blocks.

This will work:
Code:
if ($foo == 'bar')
{
   include ('bar.php');
}
else
{
   include ('baz.php');
}


This will not:
Code:
if ($foo == 'bar')
   include ('bar.php');
else
   include ('baz.php');

This is because include() is a language construct, not a function. It's also the reason why the parentheses are optional.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top