note 83769 added to function.intval
| From: | phpbenhoodidau at osu1 dot php dot net | Date: | Wed, 11 Jun 2008 00:17:34 +0000 |
| Subject: | note 83769 added to function.intval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140334@lists.php.net to get a copy of this message | ||
kris at mha dot ca:
Implicit typing. This is a feature, not a bug.
The == operator will convert your string to an int automatically (in this case) so that it is really
comparing 123 and 123, which is of course the same.
If you use the === operator then this will not occur, as it will only match on the same value and
type. This works as expected:
<?php
$tmp_array = "123,232,141";
if (intval($tmp_array) === $tmp_array)
{
echo "'".intval($tmp_array)."' equals '$tmp_array'\n";
}
else
{
echo "'".intval($tmp_array)."' does not equal
'$tmp_array'\n";
}
?>
----
Server IP: 203.88.112.146
Probable Submitter: 210.15.202.115
----
Manual Page -- http://www.php.net/manual/en/function.intval.php
Edit -- https://master.php.net/note/edit/83769
Del: integrated -- https://master.php.net/note/delete/83769/integrated
Del: useless -- https://master.php.net/note/delete/83769/useless
Del: bad code -- https://master.php.net/note/delete/83769/bad+code
Del: spam -- https://master.php.net/note/delete/83769/spam
Del: non-english -- https://master.php.net/note/delete/83769/non-english
Del: in docs -- https://master.php.net/note/delete/83769/in+docs
Del: other reasons-- https://master.php.net/note/delete/83769
Reject -- https://master.php.net/note/reject/83769
Search -- https://master.php.net/manage/user-notes.php