I am getting a variable from $_GET['category']. This is always supposed to be a integer. So when I set the variable I use:
$category=settype($_GET['category'], "int");
// Also tried
$category=settype($_GET['category'], "integer");
However, this always returns 1. They are numbers in the query string for example:
http://domain.com/example.php?category=57
When I echo $category it always returns 1. No mater what ?category= has behind it for a number.
Any help would be appreciated! Thank you!
settypemodifies the type of the variable. You’re using it as if it would return a new variable.However,
settypereturns true if the type change was successful, and false otherwise. You’re seeing the result1since that’s the string representation of true.You should either use casting, or intval: