note 82246 deleted from language.operators.comparison by danbrown

From: Date: Thu, 18 Jun 2009 14:04:00 +0000
Subject: note 82246 deleted from language.operators.comparison by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157063@lists.php.net to get a copy of this message
Note Submitter: Samaliel ---- To lukzboz ~ at ~ gmx ~ dot ~ net : It IS stated that, when compared to integers, strings are converted to a numeric value according to these rules : http://fr.php.net/manual/en/language.types.string.php Since $txt does not begin with valid numerical data, its numeric value is 0. If you try with $txt = '12 reasons I should type my variables', your code won't print anything. <?php $txt = 'yoursimpletext'; if( $txt == 0 ) { echo $txt.' == 0'; } else { echo $txt.' != 0'; } // Prints 'yoursimpletext == 0' $txt = '12 reasons I should type my variables'; if( $txt == 0 ) { echo $txt.' == 0'; } else { echo $txt.' != 0'; } // Prints '12 reasons I should type my variables != 0' var_dump( $txt ); // Prints 'string(37) "12 reasons I should type my variable" var_dump( (int) $txt ); // Prints 'int(12)' ?>

« previous php.notes (#157063) next »