Code: Select all
$var = FALSE;Code: Select all
$var = 'FALSE';I want to use $var in a conditional to test if true or false, like:
Code: Select all
if ($var)
{ echo 'TRUE!'; }
else
{ echo 'FALSE!'; }Moderator: General Moderators
Code: Select all
$var = FALSE;Code: Select all
$var = 'FALSE';Code: Select all
if ($var)
{ echo 'TRUE!'; }
else
{ echo 'FALSE!'; }Code: Select all
$var = FALSE;
if ($var === TRUE)
{ echo 'TRUE!'; }
else
{ echo 'FALSE!'; }Code: Select all
$myVar = 'abcdefg';
if($myVar){
//would be true
}
if($myVar == TRUE){
//would be true
}
if($myVar === TRUE){
//would not be true;
}Code: Select all
//given the following
$fred = 5;
$wilma = "true"'
$barney = true;
if($fred == $wilma)
{
echo "fred matches wilma<br>";
}
elseif($fred == $barney)
{
echo "fred matches barney<br>";
}
else
{
echo "No match<br>";
}
if($wilma == $barney)
{
echo "wilma matches barney<br>";
}
elseif($wilma == $fred)
{
echo "Wilma matches fred<br>";
}
else
{
echo "Wilma doesnt match anybody<br>";
}
if($fred === $barney)
{
echo "fred is like barney<br>";
}
elseif($wilma === $barney)
{
echo "Wilma matches Barney<br>";
}
else
{
echo "No matches found<br>";
}
//OK.. see if you can figure out *WHICH* values will be echoed by reading the code before peeking at the answerCode: Select all
$var = (bool) '';
$var = (bool) '0';Code: Select all
$var = (bool) 'false';
$var = (bool) 'zero';
$var = (bool) 'off';
$var = (bool) ' ';Code: Select all
if('false') {
//this will always be executed
}