note 82246 added to language.operators.comparison
| From: | Samaliel at osu1 dot php dot net | Date: | Wed, 02 Apr 2008 13:42:04 +0000 |
| Subject: | note 82246 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137860@lists.php.net to get a copy of this message | ||
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)'
?>
----
Server IP: 217.174.223.124
Probable Submitter: 193.189.91.57
----
Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php
Edit -- https://master.php.net/note/edit/82246
Del: integrated -- https://master.php.net/note/delete/82246/integrated
Del: useless -- https://master.php.net/note/delete/82246/useless
Del: bad code -- https://master.php.net/note/delete/82246/bad+code
Del: spam -- https://master.php.net/note/delete/82246/spam
Del: non-english -- https://master.php.net/note/delete/82246/non-english
Del: in docs -- https://master.php.net/note/delete/82246/in+docs
Del: other reasons-- https://master.php.net/note/delete/82246
Reject -- https://master.php.net/note/reject/82246
Search -- https://master.php.net/manage/user-notes.php