When retrieving data from a MySQL database via PHP, regardless of the field's original data type, it is always treated as a string in PHP.
To revert this behavior and obtain an integer representation of the field, employ the following techniques:
Explicit Casting:
$id = (int) $row['userid'];
intval() Function:
$id = intval($row['userid']);
By using either of these methods, you can convert the string representation of the integer field, $row['userid'], to an integer, $id.
The above is the detailed content of How Can I Treat a MySQL Integer Field as an Integer in PHP?. For more information, please follow other related articles on the PHP Chinese website!