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!
Sorry. I know this has been asked many times before, but I just have no idea what it is called/what terms to search for in order to find anything about it.
So ... if ( $variable == true ) ... and ... if ( $variable ) ... mean exactly the same thing. I didn't recall this being the case, but I guess the PHP manual doesn't lie
if you want to check if($variable == 'test') or if($variable == '1024') the if($variable) always will be true. Just an idea when people should use if($variable) and if($variable == 'something'). Does make sense?
$str_foo = 'hello';
if ($str_foo == true)
{
echo "str_foo is equal to true";
}
if ($str_foo)
{
echo "str_foo evaluates to true";
}
// will fail..
if ($str_foo === true)
{
echo "str_foo is true";
}
$str_foo = true;
if ($str_foo === true)
{
echo "str_foo is true";
}
miro_igov wrote:if you want to check if($variable == 'test') or if($variable == '1024') the if($variable) always will be true. Just an idea when people should use if($variable) and if($variable == 'something'). Does make sense?
Without using "===," if($variable) and if($variable == true) will always give the same result (as astions has kindly shown). That's the reason that we have "===."