Home > Backend Development > PHP Tutorial > PHP: Detailed explanation of integer data type examples

PHP: Detailed explanation of integer data type examples

怪我咯
Release: 2023-03-07 15:36:01
Original
5728 people have browsed it

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. .

PHP: Detailed explanation of integer data type examplesIf 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 &#39;数字1234567890不同进制的输出结果:<p>&#39;;

echo &#39;十进制的结果是:&#39;.$str1.&#39;<br/>&#39;;                      //输出十进制整数

echo &#39;十六进制的结果是:&#39;.$str2.&#39;<br/>&#39;;                    //输出十六进制整数

echo &#39;八进制的结果是:&#39;;
if($str3==$str4){                                            //判断$str3和$str4的关系
    echo &#39;$str3=$str4=&#39;.$str3;                               
}else{
    echo &#39;$str3!=$str4&#39;;
}

?>
Copy after login

Code running results:

PHP: Detailed explanation of integer data type examples

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template