Re: confused: casting a variable to integer



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
.



Relevant Pages

  • Re: PHP URI
    ... > Excuse me, I ment URL, not URI. ... Justin Koivisto, ZCE - justin@xxxxxxxxx ... Prev by Date: ...
    (comp.lang.php)
  • Re: HELP: Getting input from perl cgi to PHP.
    ... > After I had the change made, do I have restart apache? ... Justin Koivisto, ZCE - justin@xxxxxxxxx ... Prev by Date: ...
    (comp.lang.php)
  • Re: Loop after "x" seconds
    ... forgot to close the string) ... Justin Koivisto, ZCE - justin@xxxxxxxxx ... Prev by Date: ...
    (comp.lang.php)
  • Re: factory pattern in php
    ... Michael G wrote: ... Justin Koivisto, ZCE - justin@xxxxxxxxx ... Prev by Date: ...
    (comp.lang.php)
  • Re: preg help
    ... > take a regular expression as an argument. ... Justin Koivisto, ZCE - justin@xxxxxxxxx ... Prev by Date: ...
    (comp.lang.php)