How to compare string or int type?
if($_GET['choice'] == (int开发者_JAVA技巧))
or
if($_GET['choice'] == (string))
I got an error.
All GET parameters are strings. If you want to be certain that it's an integer in the string then you should sanitize it.
To check if the string $_GET['choice']
may be represented as an integer, use ctype_digit()
, eg
if (ctype_digit($_GET['choice'])) {
// integer
}
You're doing it wrong. Your example shows CASTING:
$var = (int)"15"; // casts the string 15 as an integer
If you want to compare if something is an INTEGER, you can use the is_int()
function in PHP. There are other operators that will do this for strings, arrays, etc;
http://us2.php.net/manual/en/function.is-int.php
精彩评论