Các loại dữ liệu PHP được sử dụng để chứa các loại dữ liệu hoặc giá trị khác nhau. PHP hỗ trợ 8 loại dữ liệu nguyên thủy có thể được phân loại thêm theo 3 loại:
- Các loại vô hướng [được xác định trước]
- Các loại hỗn hợp [do người dùng định nghĩa]
- Các loại đặc biệt
Kiểu dữ liệu PHP: Các loại vô hướng
Nó chỉ giữ giá trị đơn. Có 4 loại dữ liệu vô hướng trong PHP.
- boolean
- Số nguyên
- float
- sợi dây
Các loại dữ liệu PHP: Các loại hợp chất
Nó có thể giữ nhiều giá trị. Có 2 loại dữ liệu hỗn hợp trong PHP.
- mảng
- sự vật
Kiểu dữ liệu PHP: Các loại đặc biệt
Có 2 loại dữ liệu đặc biệt trong PHP.
- nguồn
- VÔ GIÁ TRỊ
PHP Boolean
Booleans là loại dữ liệu đơn giản nhất hoạt động như Switch. Nó chỉ giữ hai giá trị: true [1] hoặc false [0]. Nó thường được sử dụng với các tuyên bố có điều kiện. Nếu điều kiện là chính xác, nó sẽ trả về đúng nếu không sai.TRUE [1] or FALSE [0]. It is often used with conditional statements. If the condition is correct, it returns TRUE otherwise FALSE.
Example:
Output:
Số nguyên PHP
Số nguyên có nghĩa là dữ liệu số với dấu âm hoặc dương. Nó chỉ chứa toàn bộ số, tức là, các số không có phần phân số hoặc số thập phân.
Quy tắc cho số nguyên:
- Một số nguyên có thể là tích cực hoặc âm.
- Một số nguyên không được chứa dấu thập phân.
- Số nguyên có thể là thập phân [cơ sở 10], octal [cơ sở 8] hoặc thập lục phân [cơ sở 16].
- Phạm vi của một số nguyên phải nằm trong khoảng từ 2.147.483.648 đến 2.147.483.647, tức là, -2^31 đến 2^31.
Example:
Output:
Decimal number: 34 Octal number: 163 HexaDecimal number: 69
Php float
Một số điểm nổi là một số có điểm thập phân. Không giống như số nguyên, nó có thể giữ các số có điểm phân số hoặc thập phân, bao gồm một dấu hiệu âm hoặc dương.
Example:
Output:
Addition of floating numbers: 73.812
Chuỗi PHP
Một chuỗi là một loại dữ liệu không phải là số. Nó chứa các chữ cái hoặc bất kỳ bảng chữ cái, số và thậm chí các ký tự đặc biệt.
Giá trị chuỗi phải được đặt trong hoặc trong các trích dẫn đơn hoặc trong các trích dẫn kép. Nhưng cả hai đều được đối xử khác nhau. Để làm rõ điều này, xem ví dụ dưới đây:single quotes or in double quotes. But both are treated differently. To clarify this, see the example below:
Example:
Output:
Hello Javatpoint Hello $company
Mảng PHP
Một mảng là một loại dữ liệu hỗn hợp. Nó có thể lưu trữ nhiều giá trị của cùng một loại dữ liệu trong một biến duy nhất.
Example:
Output:
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM
Bạn sẽ tìm hiểu thêm về mảng trong các chương sau của hướng dẫn này.
Đối tượng PHP
Đối tượng là trường hợp của các lớp do người dùng xác định có thể lưu trữ cả giá trị và hàm. Họ phải được tuyên bố rõ ràng.
Example:
Output:
Bike Model: Royal Enfield
Đây là một chủ đề nâng cao của PHP, mà chúng tôi sẽ thảo luận chi tiết sau.
Tài nguyên PHP
Tài nguyên không phải là loại dữ liệu chính xác trong PHP. Về cơ bản, chúng được sử dụng để lưu trữ một số cuộc gọi chức năng hoặc tham chiếu đến tài nguyên PHP bên ngoài. Ví dụ - một cuộc gọi cơ sở dữ liệu. Nó là một tài nguyên bên ngoài.For example - a database call. It is an external resource.
Đây là một chủ đề nâng cao của PHP, vì vậy chúng tôi sẽ thảo luận chi tiết sau với các ví dụ.
PHP null
Null là một loại dữ liệu đặc biệt chỉ có một giá trị: NULL. Có một quy ước viết nó bằng chữ in hoa vì nó nhạy cảm với trường hợp.NULL. There is a convention of writing it in capital letters as it is case sensitive.
Loại đặc biệt của loại dữ liệu null xác định một biến không có giá trị.
Example:
Output:
Các loại dữ liệu xác định loại dữ liệu mà một biến có thể lưu trữ. PHP cho phép tám loại dữ liệu khác nhau. Tất cả chúng được thảo luận dưới đây. Có các loại dữ liệu đặc biệt được xác định trước, do người dùng định nghĩa và người dùng.
Các loại dữ liệu được xác định trước là:
- Boolean
- Số nguyên
- Kép
- Sợi dây
Các loại dữ liệu do người dùng xác định [hợp chất] là:
- Mảng
- Các đối tượng
Các loại dữ liệu đặc biệt là:
- VÔ GIÁ TRỊ
- nguồn
Năm đầu tiên được gọi là các loại dữ liệu đơn giản và ba loại cuối cùng là các loại dữ liệu hỗn hợp: & nbsp; & nbsp;
1. Số nguyên: Số nguyên chỉ chứa các số toàn bộ bao gồm các số dương và số âm, tức là, các số không có phần phân số hoặc dấu thập phân. Chúng có thể là thập phân [cơ sở 10], bát phân [cơ sở 8] hoặc thập lục phân [cơ sở 16]. Cơ sở mặc định là thập phân [cơ sở 10]. Các số nguyên bát phân có thể được khai báo với hàng đầu 0 và thập lục phân có thể được khai báo với hàng đầu 0x. Phạm vi số nguyên phải nằm trong khoảng -2^31 đến 2^31. & nbsp;: Integers hold only whole numbers including positive and negative numbers, i.e., numbers without fractional part or decimal point. They can be decimal [base 10], octal [base 8], or hexadecimal [base 16]. The default base is decimal [base 10]. The octal integers can be declared with leading 0 and the hexadecimal can be declared with leading 0x. The range of integers must lie between -2^31 to 2^31.
Example:
PHP
Addition of floating numbers: 73.8120
Addition of floating numbers: 73.8121
Addition of floating numbers: 73.8122
Addition of floating numbers: 73.8123
Addition of floating numbers: 73.8124
Addition of floating numbers: 73.8125
Addition of floating numbers: 73.8126
Addition of floating numbers: 73.8127
Addition of floating numbers: 73.8128
Addition of floating numbers: 73.8129
Hello Javatpoint Hello $company0
Addition of floating numbers: 73.8121
Hello Javatpoint Hello $company2
Addition of floating numbers: 73.8123
Hello Javatpoint Hello $company4
Hello Javatpoint Hello $company5
Addition of floating numbers: 73.8129
Hello Javatpoint Hello $company4
Hello Javatpoint Hello $company5
Hello Javatpoint Hello $company9
Hello Javatpoint Hello $company4
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM1
Addition of floating numbers: 73.8129
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM3
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM4
2. Double: Có thể giữ các số chứa các phần phân số hoặc thập phân bao gồm số dương và số âm hoặc một số ở dạng hàm mũ. Theo mặc định, các biến thêm một số lượng tối thiểu các vị trí thập phân. Kiểu dữ liệu kép giống như một chiếc phao như số điểm nổi hoặc số thực.: Can hold numbers containing fractional or decimal parts including positive and negative numbers or a number in exponential form. By default, the variables add a minimum number of decimal places. The Double data type is the same as a float as floating-point numbers or real numbers.
Example:
PHP
Addition of floating numbers: 73.8120
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM6
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM7
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM8
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM9
Addition of floating numbers: 73.8129
Hello Javatpoint Hello $company0
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM6
Hello Javatpoint Hello $company2
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM8
Hello Javatpoint Hello $company4
Hello Javatpoint Hello $company5
Addition of floating numbers: 73.8129
Hello Javatpoint Hello $company4
Hello Javatpoint Hello $company5
Hello Javatpoint Hello $company9
Hello Javatpoint Hello $company4
2. Double: Có thể giữ các số chứa các phần phân số hoặc thập phân bao gồm số dương và số âm hoặc một số ở dạng hàm mũ. Theo mặc định, các biến thêm một số lượng tối thiểu các vị trí thập phân. Kiểu dữ liệu kép giống như một chiếc phao như số điểm nổi hoặc số thực.
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM4
Đầu ra
705.11 float[705.11]
7. NULL: Đây là những loại biến đặc biệt chỉ có thể chứa một giá trị, tức là null. Chúng tôi tuân theo quy ước viết nó ở dạng vốn, nhưng nó nhạy cảm với trường hợp. Nếu một biến được tạo mà không có giá trị hoặc không có giá trị, nó sẽ tự động được gán giá trị null. Nó được viết bằng chữ in hoa.: Hold letters or any alphabets, even numbers are included. These are written within double quotes during declaration. The strings can also be written within single quotes, but they will be treated differently while printing variables. To clarify this look at the example below.
Example:
PHP
Ví dụ: & nbsp;
Addition of floating numbers: 73.81250
Addition of floating numbers: 73.81251
Hello Javatpoint Hello $company5
The name of the Geek is Krishna The name of the geek is $name string[7] "Krishna"2
Hello Javatpoint Hello $company4
Hello Javatpoint Hello $company5
The name of the Geek is Krishna The name of the geek is $name string[7] "Krishna"5
Hello Javatpoint Hello $company4
Hello Javatpoint Hello $company5
Hello Javatpoint Hello $company9
Hello Javatpoint Hello $company4
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM1
705.11 float[705.11]7
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM3
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM4
Đầu ra
The name of the Geek is Krishna The name of the geek is $name string[7] "Krishna"
4. Boolean: Các loại dữ liệu Boolean được sử dụng trong thử nghiệm có điều kiện. Chỉ giữ hai giá trị, đúng [1] hoặc sai [0]. Các sự kiện thành công sẽ trả về các sự kiện đúng và không thành công trở lại sai. Giá trị loại NULL cũng được coi là sai trong boolean. Ngoài NULL, 0 cũng được coi là sai trong Boolean. Nếu một chuỗi trống thì nó cũng được coi là sai trong kiểu dữ liệu boolean. & Nbsp;: Boolean data types are used in conditional testing. Hold only two values, either TRUE[1] or FALSE[0]. Successful events will return true and unsuccessful events return false. NULL type values are also treated as false in Boolean. Apart from NULL, 0 is also considered false in boolean. If a string is empty then it is also considered false in boolean data type.
Ví dụ: & nbsp; & nbsp;
PHP
Addition of floating numbers: 73.8120
This condition is TRUE5
This condition is TRUE6
This condition is TRUE7
Hello Javatpoint Hello $company5
This condition is TRUE9
Hello Javatpoint Hello $company4
This condition is TRUE5
First Element: 10 Second Element: 20 Third Element: 30 array[3] { [0]=> int[10] [1]=> int[20] [2]=> int[30] }2
This condition is TRUE7
Hello Javatpoint Hello $company5
First Element: 10 Second Element: 20 Third Element: 30 array[3] { [0]=> int[10] [1]=> int[20] [2]=> int[30] }5
Hello Javatpoint Hello $company4
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM4
Đầu ra
This condition is TRUE
4. Boolean: Các loại dữ liệu Boolean được sử dụng trong thử nghiệm có điều kiện. Chỉ giữ hai giá trị, đúng [1] hoặc sai [0]. Các sự kiện thành công sẽ trả về các sự kiện đúng và không thành công trở lại sai. Giá trị loại NULL cũng được coi là sai trong boolean. Ngoài NULL, 0 cũng được coi là sai trong Boolean. Nếu một chuỗi trống thì nó cũng được coi là sai trong kiểu dữ liệu boolean. & Nbsp;: Array is a compound data type that can store multiple values of the same data type. Below is an example of an array of integers. It combines a series of data that are related together.
PHP
Addition of floating numbers: 73.8120
This condition is TRUE7
Hello Javatpoint Hello $company5
This condition is TRUE9
Hello Javatpoint Hello $company4
This condition is TRUE7
Hello Javatpoint Hello $company5
First Element: 10 Second Element: 20 Third Element: 30 array[3] { [0]=> int[10] [1]=> int[20] [2]=> int[30] }5
Hello Javatpoint Hello $company4
5. Mảng: Mảng là một loại dữ liệu ghép có thể lưu trữ nhiều giá trị của cùng một loại dữ liệu. Dưới đây là một ví dụ về một loạt các số nguyên. Nó kết hợp một loạt dữ liệu có liên quan với nhau. & Nbsp; & nbsp;
First Element: 10 Second Element: 20 Third Element: 30 array[3] { [0]=> int[10] [1]=> int[20] [2]=> int[30] }9
Hello Javatpoint Hello $company0
This is an example of Object Data Type!1
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM1
First Element: 10 Second Element: 20 Third Element: 30 array[3] { [0]=> int[10] [1]=> int[20] [2]=> int[30] }9
Addition of floating numbers: 73.81204
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM4
Đầu ra
First Element: 10 Second Element: 20 Third Element: 30 array[3] { [0]=> int[10] [1]=> int[20] [2]=> int[30] }
4. Boolean: Các loại dữ liệu Boolean được sử dụng trong thử nghiệm có điều kiện. Chỉ giữ hai giá trị, đúng [1] hoặc sai [0]. Các sự kiện thành công sẽ trả về các sự kiện đúng và không thành công trở lại sai. Giá trị loại NULL cũng được coi là sai trong boolean. Ngoài NULL, 0 cũng được coi là sai trong Boolean. Nếu một chuỗi trống thì nó cũng được coi là sai trong kiểu dữ liệu boolean. & Nbsp;
Ví dụ: & nbsp; & nbsp;: Objects are defined as instances of user-defined classes that can hold both values and functions and information for data processing specific to the class. This is an advanced topic and will be discussed in detail in further articles. When the objects are created, they inherit all the properties and behaviours from the class, having different values for all the properties.
PHP
PHP
Addition of floating numbers: 73.8120
This condition is TRUE7
Hello Javatpoint Hello $company5
This condition is TRUE9
Hello Javatpoint Hello $company4
This condition is TRUE7
Hello Javatpoint Hello $company5
First Element: 10 Second Element: 20 Third Element: 30 array[3] { [0]=> int[10] [1]=> int[20] [2]=> int[30] }5
Hello Javatpoint Hello $company4
5. Mảng: Mảng là một loại dữ liệu ghép có thể lưu trữ nhiều giá trị của cùng một loại dữ liệu. Dưới đây là một ví dụ về một loạt các số nguyên. Nó kết hợp một loạt dữ liệu có liên quan với nhau. & Nbsp; & nbsp;
This condition is TRUE7
Addition of floating numbers: 73.81219
Addition of floating numbers: 73.81220
Addition of floating numbers: 73.81211
Hello Javatpoint Hello $company4
Addition of floating numbers: 73.81209
Addition of floating numbers: 73.81224
First Element: 10 Second Element: 20 Third Element: 30 array[3] { [0]=> int[10] [1]=> int[20] [2]=> int[30] }9
Hello Javatpoint Hello $company0
This is an example of Object Data Type!1
Hello Javatpoint Hello $company5
This is an example of Object Data Type!4
Hello Javatpoint Hello $company4
Addition of floating numbers: 73.81209
Addition of floating numbers: 73.81224
Addition of floating numbers: 73.81224
Hello Javatpoint Hello $company5
This is an example of Object Data Type!7
Hello Javatpoint Hello $company4
Hello Javatpoint Hello $company5
Addition of floating numbers: 73.81200
Hello Javatpoint Hello $company4
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM4
Đầu ra
This is an example of Object Data Type!
4. Boolean: Các loại dữ liệu Boolean được sử dụng trong thử nghiệm có điều kiện. Chỉ giữ hai giá trị, đúng [1] hoặc sai [0]. Các sự kiện thành công sẽ trả về các sự kiện đúng và không thành công trở lại sai. Giá trị loại NULL cũng được coi là sai trong boolean. Ngoài NULL, 0 cũng được coi là sai trong Boolean. Nếu một chuỗi trống thì nó cũng được coi là sai trong kiểu dữ liệu boolean. & Nbsp; These are special types of variables that can hold only one value i.e., NULL. We follow the convention of writing it in capital form, but it’s case-sensitive. If a variable is created without a value or no value, it is automatically assigned a value of NULL. It is written in capital letters.
Ví dụ: & nbsp; & nbsp;
PHP
Addition of floating numbers: 73.8120
This condition is TRUE7
Hello Javatpoint Hello $company5
This condition is TRUE9
Hello Javatpoint Hello $company4
This condition is TRUE7
Hello Javatpoint Hello $company5
First Element: 10 Second Element: 20 Third Element: 30 array[3] { [0]=> int[10] [1]=> int[20] [2]=> int[30] }5
Hello Javatpoint Hello $company4
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM1
Addition of floating numbers: 73.81250
Addition of floating numbers: 73.81204
array[3] { [0]=> string[13] "Royal Enfield" [1]=> string[6] "Yamaha" [2]=> string[3] "KTM" } Array Element1: Royal Enfield Array Element2: Yamaha Array Element3: KTM4
5. Mảng: Mảng là một loại dữ liệu ghép có thể lưu trữ nhiều giá trị của cùng một loại dữ liệu. Dưới đây là một ví dụ về một loạt các số nguyên. Nó kết hợp một loạt dữ liệu có liên quan với nhau. & Nbsp; & nbsp;: Resources in PHP are not an exact data type. These are basically used to store references to some function call or to external PHP resources. For example, consider a database call. This is an external resource. Resource variables hold special handles for files and database
connections.
We will discuss resources in detail in further articles.
Note:
First Element: 10 Second Element: 20 Third Element: 30 array[3] { [0]=> int[10] [1]=> int[20] [2]=> int[30] }
9Hello Javatpoint Hello $company
0This is an example of Object Data Type!
1 var_dump[] function which dumps information about a variable.Hello Javatpoint Hello $company
5This is an example of Object Data Type!
4Hello Javatpoint Hello $company
4
Hello Javatpoint Hello $company5
This is an example of Object Data Type!7
Hello Javatpoint Hello $company4Chinmoy Lenka. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or if you want to share more information about the topic discussed above.