Hướng dẫn how many datatypes are there in php? - có bao nhiêu kiểu dữ liệu trong php?
Kiểu dữ liệu PHPCác biến có thể lưu trữ dữ liệu của các loại khác nhau và các loại dữ liệu khác nhau có thể làm những việc khác nhau. Show
PHP hỗ trợ các loại dữ liệu sau:
Chuỗi PHPMột chuỗi là một chuỗi các nhân vật, như "Hello World!". Một chuỗi có thể là bất kỳ văn bản bên trong trích dẫn. Bạn có thể sử dụng trích dẫn đơn hoặc đôi: Thí dụ$x = "Hello world!"; echo $ x; echo ""; Echo $ y;?> Hãy tự mình thử » Số nguyên PHPMột loại dữ liệu số nguyên là một số không phân giải trong khoảng -2,147,483,648 đến 2.147.483.647. Quy tắc cho số nguyên:
Trong ví dụ sau $ x là một số nguyên. Hàm php var_dump () trả về kiểu dữ liệu và giá trị: Php floatMột chiếc phao (số điểm nổi) là một số có điểm thập phân hoặc một số ở dạng theo cấp số nhân. Trong ví dụ sau $ x là một chiếc phao. Hàm php var_dump () trả về kiểu dữ liệu và giá trị: PHP BooleanMột boolean đại diện cho hai trạng thái có thể: đúng hoặc sai. Booleans thường được sử dụng trong thử nghiệm có điều kiện. Bạn sẽ tìm hiểu thêm về thử nghiệm có điều kiện trong một chương sau của hướng dẫn này. Mảng PHPMột mảng lưu trữ nhiều giá trị trong một biến duy nhất. Trong các ví dụ sau đây $ Cars là một mảng. Hàm php var_dump () trả về kiểu dữ liệu và giá trị: Thí dụ$cars = array("Volvo","BMW","Toyota"); Hãy tự mình thử » Số nguyên PHP Một loại dữ liệu số nguyên là một số không phân giải trong khoảng -2,147,483,648 đến 2.147.483.647.Quy tắc cho số nguyên: Một số nguyên phải có ít nhất một chữ số Một số nguyên không được có một điểm thập phân Một số nguyên có thể là tích cực hoặc âm Các số nguyên có thể được chỉ định trong: thập phân (cơ sở 10), thập lục phân (cơ sở 16), octal (cơ sở 8) hoặc ký hiệu nhị phân (cơ sở 2) Trong ví dụ sau $ x là một số nguyên. Hàm php var_dump () trả về kiểu dữ liệu và giá trị: Thí dụclass Car { echo $ x; echo ""; Echo $ y;?> Hãy tự mình thử » Số nguyên PHPMột loại dữ liệu số nguyên là một số không phân giải trong khoảng -2,147,483,648 đến 2.147.483.647. Quy tắc cho số nguyên: Một số nguyên phải có ít nhất một chữ số If a variable is created without a value, it is automatically assigned a value of NULL. Một số nguyên không được có một điểm thập phân Một số nguyên có thể là tích cực hoặc âmCác số nguyên có thể được chỉ định trong: thập phân (cơ sở 10), thập lục phân (cơ sở 16), octal (cơ sở 8) hoặc ký hiệu nhị phân (cơ sở 2) Trong ví dụ sau $ x là một số nguyên. Hàm php var_dump () trả về kiểu dữ liệu và giá trị: Php float Có bao nhiêu loại dữ liệu trong PHP? 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 hợp chất (được xác định trước) (định nghĩa người dùng) Các loại đặc biệt.
Các loại dữ liệu được chia thành hai nhóm: các loại dữ liệu nguyên thủy - bao gồm byte, ngắn, int, dài, float, gấp đôi, boolean và char. Các loại dữ liệu không định tuyến - chẳng hạn như chuỗi, mảng và lớp (bạn sẽ tìm hiểu thêm về những loại này trong một chương sau)
Điểm nổi (Float) ....
Boolean (Bool) .... Loại liệt kê (Enum) ....: 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
The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"0 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"1 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"2 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"3 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"4 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"5 $deci1 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"7 $deci2 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"9 This condition is TRUE0 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"4 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"9 This condition is TRUE0 This condition is TRUE4 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"9 This condition is TRUE6 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"4 This condition is TRUE8 This condition is TRUE9 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: PHPFirst Element: 10 Second Element: 20 Third Element: 30 array(3) { [0]=> int(10) [1]=> int(20) [2]=> int(30) }1 First Element: 10 Second Element: 20 Third Element: 30 array(3) { [0]=> int(10) [1]=> int(20) [2]=> int(30) }2 First Element: 10 Second Element: 20 Third Element: 30 array(3) { [0]=> int(10) [1]=> int(20) [2]=> int(30) }3 First Element: 10 Second Element: 20 Third Element: 30 array(3) { [0]=> int(10) [1]=> int(20) [2]=> int(30) }4 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"4 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"5 First Element: 10 Second Element: 20 Third Element: 30 array(3) { [0]=> int(10) [1]=> int(20) [2]=> int(30) }1 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"7 First Element: 10 Second Element: 20 Third Element: 30 array(3) { [0]=> int(10) [1]=> int(20) [2]=> int(30) }3 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"9 This condition is TRUE0 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"4 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"9 This condition is TRUE0 This condition is TRUE4 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"9 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. This condition is TRUE9
705.11 float(705.11)
Example: PHPThe name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"4 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"5 First Element: 10 Second Element: 20 Third Element: 30 array(3) { [0]=> int(10) [1]=> int(20) [2]=> int(30) }1 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"7 First Element: 10 Second Element: 20 Third Element: 30 array(3) { [0]=> int(10) [1]=> int(20) [2]=> int(30) }3 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"9 This condition is TRUE6 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"4 This condition is TRUE8 Đầu ra 3. Chuỗi: Giữ chữ cái hoặc bất kỳ bảng chữ cái nào, thậm chí các số được bao gồm. Chúng được viết trong các trích dẫn kép trong quá trình tuyên bố. Các chuỗi cũng có thể được viết trong các trích dẫn đơn, nhưng chúng sẽ được xử lý khác nhau trong khi in các biến. Để làm rõ cái nhìn này vào ví dụ dưới đây. & Nbsp; & nbsp; This condition is TRUE0 This condition is TRUE4 The name of the Geek is Krishna The name of the geek is $name string(7) "Krishna"9 This condition is TRUE6 2 |