note 90033 added to control-structures.if
| From: | Anonymous at osu1 dot php dot net | Date: | Thu, 02 Apr 2009 12:32:28 +0000 |
| Subject: | note 90033 added to control-structures.if | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152749@lists.php.net to get a copy of this message | ||
If you need to do something when a function return FALSE and nothing when it return TRUE you can do
it like that :
<?php
function call()
{
return FALSE;
}
if(call()==TRUE) // or if(call())
{
// nothing to do
}
else
{
// do something here
}
?>
You can also write it like this :
<?php
if(!call()==TRUE) // or if(!call())
{
// do something here
}
// here '!' will invert 'FALSE' (from call()) into 'TRUE'
?>
/!\ WARNING /!\
The '!' only work with booleans !
Check http://fr.php.net/manual/en/language.types.boolean.php
to know if you can use '!'
If you want to compare two strings and use '!' be careful how you use it !!!!
<?php
$string1 = "cake";
$string2 = "foo";
if(!$string1==$string2)
{
echo "cake is a lie";
}
//this will ALWAYS fail without exception because '!' is applied to $string1 and not to
'$string1==$string2'
//to work, you have to do like this
if(!($string1==$string2))
{
echo "cake is a lie";
}
//it will display 'cake is a lie' because ($string1==$string2) return FALSE and
'!' will invert it into TRUE
?>
For array/float, it's the same !
----
Server IP: 89.31.146.176
Probable Submitter: 193.251.36.211
----
Manual Page -- http://www.php.net/manual/en/control-structures.if.php
Edit -- https://master.php.net/note/edit/90033
Del: integrated -- https://master.php.net/note/delete/90033/integrated
Del: useless -- https://master.php.net/note/delete/90033/useless
Del: bad code -- https://master.php.net/note/delete/90033/bad+code
Del: spam -- https://master.php.net/note/delete/90033/spam
Del: non-english -- https://master.php.net/note/delete/90033/non-english
Del: in docs -- https://master.php.net/note/delete/90033/in+docs
Del: other reasons-- https://master.php.net/note/delete/90033
Reject -- https://master.php.net/note/reject/90033
Search -- https://master.php.net/manage/user-notes.php