Re: intval
| From: | Robert Cummings | Date: | Sat, 09 May 2009 15:02:03 +0000 |
| Subject: | Re: intval | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-292420@lists.php.net to get a copy of this message | ||
On Sat, 2009-05-09 at 20:02 +0530, kranthi wrote:
> thanks for the reply... just happened to see
> http://php.net/ternary
> which explains the above result
>
> i want to explicitly type cast all the numbers passed via post (by
> default they are strings)
> is_numeric() is a option, but it will not be possible to differentiate
> between int and float.
>
> $_POST['month'] !== (string)(int)$_POST['month']
> this is exactly what i want... but wont this take up memory when used
> with array_walk_recursive() ?
Just add the value to 0 and PHP will do the juggling for you:
<?php
$_POST = array( '1', '100', '100.1', '100.123' );
foreach( $_POST as $value )
{
$value = 0 + $value;
echo 'Value: ';
var_dump( $value );
}
?>
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP