note 76493 added to function.intval
| From: | kris at mha dot ca | Date: | Tue, 17 Jul 2007 22:41:44 +0000 |
| Subject: | note 76493 added to function.intval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128677@lists.php.net to get a copy of this message | ||
More intval wierdness (tested with PHP 5.2.3 and 4.3.10).
<?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";
}
?>
Output:
'123' equals '123,232,141'
Odd. Not what was expected. Maybe if I put it into a temporary variable it will normalize itself.
<?php
$tmp_array = "123,232,141";
$tmp = intval($tmp_array);
if ($tmp == $tmp_array)
{
echo "'$tmp' equals '$tmp_array'\n";
}
else
{
echo "'$tmp' does not equal '$tmp_array'\n";
}
?>
Output:
'123' equals '123,232,141'
I don't know if this is a feature, or a bug in PHP (I would certainly classify this as a bug,
but since it is in both PHP 4 and PHP 5 maybe not). If it is a feature, could someone explain it to
me?
----
Server IP: 66.207.199.35
Probable Submitter: 216.18.67.130
----
Manual Page -- http://www.php.net/manual/en/function.intval.php
Edit -- https://master.php.net/note/edit/76493
Del: integrated -- https://master.php.net/note/delete/76493/integrated
Del: useless -- https://master.php.net/note/delete/76493/useless
Del: bad code -- https://master.php.net/note/delete/76493/bad+code
Del: spam -- https://master.php.net/note/delete/76493/spam
Del: non-english -- https://master.php.net/note/delete/76493/non-english
Del: in docs -- https://master.php.net/note/delete/76493/in+docs
Del: other reasons-- https://master.php.net/note/delete/76493
Reject -- https://master.php.net/note/reject/76493
Search -- https://master.php.net/manage/user-notes.php