Link is: /example.php?id=1, no space after 1.

if (isset($_GET["id"])) {
    $id = $_GET["id"];
    echo !is_int($_GET["id"]);   // yields "1" (true) !!!
}

Ask me whatever you need.

I check to make sure that my system didn't go crazy !is_int(1) yields false. So... I don't know...

Maybe $_GET passes "1" instead of 1. But how do I cast integer in PHP, when it's all handled in background?

Edit: string(1) "1", yep, string. How can I check $_GET["id"] as integer against is_int()?

is_int(1) should return true since 1 is an int primitive. However, is_int("1") should return false because you are checking a string (that happens to have a numeric character, but is a string nevertheless).

A form's input (as in $_POST['id']) or url parameter (as in $_GET['id']) is always a string, even if it has a numeric value. What you need is is_numeric().

if ( array_key_exists('id',$_GET) && is_numeric($_GET['id']) ) {
    $id = intval( $_GET['id'] );
    echo is_int( $id );
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.