Re: confused: casting a variable to integer
- From: Justin Koivisto <justin@xxxxxxxxx>
- Date: Tue, 29 Nov 2005 14:34:53 -0600
Sean wrote:
> See the differece if you use ===
>
> <?
> $name="henk";
>
> echo "\$name=$name <br>";
> echo "(int)\$name=".(int)$name."<br>";
>
> if ($name === (int)$name){
> echo "equal";
> } else {
> echo "Not equal";
> }
>
> ?>
>
> http://php.net/operators.comparison
>
But be careful with this...
$i="4";
if($i === intval($i)){
// this will not happen
}
Also keep in mind that values that are supplied via _GET, _POST, _COOKIE
are strings, not their representative types...
Therefore:
call page: page.php?i=4
if($_GET['i'] === intval($_GET['i'])){
// this will not happen
}
--
Justin Koivisto, ZCE - justin@xxxxxxxxx
http://koivi.com
.
- References:
- confused: casting a variable to integer
- From: Erwin Moller
- Re: confused: casting a variable to integer
- From: Sean
- confused: casting a variable to integer
- Prev by Date: Re: PHP/Apache or IE problem (no GPC data)
- Next by Date: Re: Reading from txt file
- Previous by thread: Re: confused: casting a variable to integer
- Next by thread: Sort array from a Query
- Index(es):
Relevant Pages
|