lol I forgot

phpBB3 and MOD challenges setup by the staff to test and challenge your phpBB3 coding skills.

lol I forgot

Postby Synaptic Anarchy » 15 Jun 2007, 18:29

Highway and I were talking about this earlier.

Was it
Code: Select all
if ($x) {
     include(myfile.php);
};


To include a file only if x variable was true?
It's winter.
User avatar
Synaptic Anarchy    
Lieutenant Commander
Lieutenant Commander
 
Posts: 351
Joined: 02 Jul 2006, 02:39
Favorite Team: Starfleet Design :P
Gender: Male




phpBB Academy at StarTrekGuide
Support STG
Using PayPal Donate

Re: lol I forgot

Postby Highway of Life » 15 Jun 2007, 20:17

Okay, yeah... I got busy so was not able to finish.

it?s:
Code: Select all
if (condition)
{
    include(
'my_special_file.php');
}  
of course, in phpBB3, it would be:
Code: Select all
if (condition)
{
    include(
"{$phpbb_root_path}my_special_file.$phpEx");
}  


As for the === expression, that is it must match both value and type.
For example...
Code: Select all
<?php
$a 
0// var type is int
$d false// var type is bool (or boolean)
$c ''// var type is string

// an if statement tests a (condition) and if it is true, whatever is inside the { } is performed.
if ($a === false// since $a is not exactly false, this condition evaluates to false
{
    echo 
'$a is exactly false';
}
else 
{
    echo 
'$a is not exactly false';
}
// will echo '$a is not exactly false'

// since the double equal just tests for the value, the following expression will evaluate to true...
if ($a == false)
{
    echo 
'$a is false';
}
// will echo '$a has the value of false'

if ($d === false// since $d is a bool, and we are testing for bool, the expression evaluates to true
{
    echo 
'$d is exactly false';
}
// will echo '$d is exactly false';
?>


for more details on variable types, see f71-starfleet-academy-campus/t1771-mixed-variable-types-challenge-and-quiz.html
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10


Return to phpBB3 Challenges at phpBB Academy

Who is online

Users browsing this forum: No registered users and 1 guest