note 76803 added to function.intval

From: Date: Tue, 31 Jul 2007 13:15:27 +0000
Subject: note 76803 added to function.intval
Groups: php.notes 
Request: Send a blank email to php-notes+get-129075@lists.php.net to get a copy of this message
@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 ---- Server IP: 208.69.120.35 Probable Submitter: 62.251.92.22 ---- Manual Page -- http://www.php.net/manual/en/function.intval.php Edit -- https://master.php.net/note/edit/76803 Del: integrated -- https://master.php.net/note/delete/76803/integrated Del: useless -- https://master.php.net/note/delete/76803/useless Del: bad code -- https://master.php.net/note/delete/76803/bad+code Del: spam -- https://master.php.net/note/delete/76803/spam Del: non-english -- https://master.php.net/note/delete/76803/non-english Del: in docs -- https://master.php.net/note/delete/76803/in+docs Del: other reasons-- https://master.php.net/note/delete/76803 Reject -- https://master.php.net/note/reject/76803 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129075) next »