What is an integer data type?
The integer data type is what we often call integers. It can only be integers. Like we wrote 123456, my age 20. This is an integer type, or -123456, which all represent integer types. We write these in decimal. We can also write octal
numbers, hexadecimal System, these all represent integers. If you use octal representation, you must add 0 in front of the number. If you use hexadecimal, you need to add 0x.
The integer type must have a valid range, and the valid range is -2447483648~+2147483647
Since there is a storage range, let us now say that the addition of two integers must be equal to an integer? Not necessarily, because exceeding the storage range of integers will produce a phenomenon called overflow. What does it mean? Let us say, take a one-liter cup and you
want to hold ten liters of water, it will definitely not be able to hold it and it will leak out. So since you want to hold ten liters of water , you can only use a larger container. Therefore, when the given value exceeds the maximum range that can be expressed by the int type, it will be treated as a float
type. The storage range of the floating point type is larger than that of the integer type. .
If illegal numbers (8 and 9) appear in octal, the following numbers will be ignored.
Integer data type example
In the following example, the results in octal, decimal and hexadecimal will be output respectively: the code is as follows
<?php header("Content-type:text/html;charset=utf-8"); //设置编码 $str1=1234567890; //说明一个十进制整数 $str2=0x1234567890; //说明一个十六进制的整数 $str3=01234567890; //说明一个八进制的整数 $str4=01234567; //说明另一个八进制的整数 echo '数字1234567890不同进制的输出结果:<p>'; echo '十进制的结果是:'.$str1.'<br/>'; //输出十进制整数 echo '十六进制的结果是:'.$str2.'<br/>'; //输出十六进制整数 echo '八进制的结果是:'; if($str3==$str4){ //判断$str3和$str4的关系 echo '$str3=$str4='.$str3; }else{ echo '$str3!=$str4'; } ?>
Code running results:
The above is the result of outputting integers in different bases. In the next section, we will introduce to you the "" in the scalar data type. Float type (float) ".
The above is the detailed content of PHP: Detailed explanation of integer data type examples. For more information, please follow other related articles on the PHP Chinese website!