Re: Converting variables to integer
| From: | Marek Kilimajer | Date: | Wed, 06 Nov 2002 18:54:34 +0000 |
| Subject: | Re: Converting variables to integer | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-123042@lists.php.net to get a copy of this message | ||
This should work for you, this recursive function loops the array,
if it gets array again, calls itself
function convert2int($var) {
foreach($var as $k => $v ) {
if(is_array($v)) {
$var[$k]=convert2int($v);
} else {
$var[$k]=str_replace(',',$v);
}
}
return $var;
}
$_POST=convert2int($_POST);
drparker@clam.rutgers.edu wrote:
I have a bunch of form variables that I need to process as integers. The problem is that some users are writing in values with commas - e.g. 100,000, and that isn't read as an integer. There's more than one variable so I don't want to have to do a string replace for each one. Is there a general way to curb this problem? Thanks, Doug