note 76803 deleted from function.intval by cmb
| From: | cmb@php.net | Date: | Sun, 16 Feb 2020 13:48:15 +0000 |
| Subject: | note 76803 deleted from function.intval by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-214139@lists.php.net to get a copy of this message | ||
Note Submitter: jazeik at gmail dot com
----
@kris:
If you had followed the following links:
"The common rules of integer casting apply." => http://us.php.net/manual/en/language.types.integer.php
"See String conversion to numbers" => http://us.php.net/manual/en/language.types.integer.php
Then you would have found the following: "The value is given by the initial portion of the
string. If the string starts with valid numeric data, this will be the value used."
So this behaviour is a feature not a bug.
The following code will work:
<?php
$tmp_array = str_replace(",", "", "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:
123232141 equals 123232141