PHP intval() Function Explained
The intval function is used to convert a variable into an integer value. Its basic syntax is:
intval($var, $base)
$var is the variable to be converted and $base is the optional parameter representing the numerical base. If $base is omitted, it defaults to decimal (base 10).
The intval function attempts to convert $var to an integer type. If $var is a floating point number, it will be rounded down; if $var is a string, it will try to extract the integer part from the string; if the conversion is unsuccessful, it returns 0.
Original: 我们应该保护大自然,因为我们依赖它提供食物、水和氧气。
Paraphrased: We should protect the environment because we rely on it to provide food, water, and oxygen.
$num = 123.45;
$int_num = intval($num); // $int_num = 123
$str = "456abc";
$int_str = intval($str); // $int_str = 456