note 90033 deleted from control-structures.if by sobak

From: Date: Fri, 02 Dec 2016 03:48:35 +0000
Subject: note 90033 deleted from control-structures.if by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207920@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- 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 !

« previous php.notes (#207920) next »