Các phương thức này được sử dụng để xác định giá trị của một biến. Để xem một biến có giá trị hay không, hãy sử dụng các hàm isset[], empty[] và is null[]
Các hàm isset[], empty[] và is null[] là các hàm dựng sẵn trong PHP được sử dụng để kiểm tra giá trị của một biến hoặc quá trình khởi tạo của nó. Tất cả các chức năng này trả về một giá trị Boolean. Ở đây, tôi sẽ giải thích sự khác biệt giữa các chức năng này
Bảng chênh lệch chức năng
Method Name "" "phpflow" NULL FALSE 0 undefined empty[] TRUE FALSE TRUE TRUE TRUE TRUE is_null[] FALSE FALSE TRUE FALSE FALSE ERROR isset[] TRUE TRUE FALSE TRUE TRUE FALSE
Hàm khởi tạo PHP []
Phương pháp
Value of variable is set Array is Empty0 này được sử dụng để xác định xem một biến có được đặt và không phải là NULL hay không. Bạn có thể đọc tài liệu isset[]
Hàm này trả về kết quả là giá trị Boolean Đúng hoặc Sai
cú pháp
Value of variable is set Array is Empty1
Ví dụ về hàm isset[] trong PHP
$age = 0; // Evaluates as true because $age is set if [isset[$age]] { echo '$age is set even though it is empty'; }
đầu ra
$age is set even though it is empty
Hàm PHP rỗng []
Phương thức trống [] cũng là một phương thức tích hợp được sử dụng để xác định xem một biến có được đặt và không trống không
Nếu giá trị là một chuỗi rỗng, sai, mảng [], NULL, 0 và không được đặt thì hàm trống [] trả về TRUE và nếu một giá trị không trống thì trả về FALSE
Hàm empty[] là một hàm có sẵn trong PHP dùng để kiểm tra một biến có rỗng hay không
Các giá trị này được coi là giá trị rỗng
- “” [một chuỗi rỗng]
- 0 [ 0 là số nguyên]
- 0. 0 [ 0 dưới dạng số float]
- “0” [ 0 dưới dạng chuỗi]
- VÔ GIÁ TRỊ
- SAI
- mảng[] [một mảng trống]
Thí dụ. Ví dụ dưới đây minh họa hàm empty[] trong PHP
PHP
Value of variable is set Array is Empty2
Value of variable is set Array is Empty3____34
Value of variable is set Array is Empty3____36
Value of variable is set Array is Empty3
Value of variable is set Array is Empty8
Value of variable is set Array is Empty0
Value of variable is set Array is Empty3______32
Value of variable is set Array is Empty3
Value of variable is set Array is Empty3
Value of variable is set Array is Empty5
Value of variable is set Array is Empty6
Value of variable is set Array is Empty7
Value of variable is set Array is Empty8
________ 33 ________ 100 ________ 101
________ 33 ________ 103 ________ 104
Value of variable is set Array is Empty3____106
Value of variable is set Array is Empty6
$age = 0; // Evaluates as true because $age is set if [isset[$age]] { echo '$age is set even though it is empty'; }08
$age = 0; // Evaluates as true because $age is set if [isset[$age]] { echo '$age is set even though it is empty'; }09
Value of variable is set Array is Empty3____321
Value of variable is set Array is Empty6____323
Value of variable is set Array is Empty8
Value of variable is set Array is Empty3____326
____33______328____329
Value of variable is set Array is Empty8____331
Value of variable is set Array is Empty32____333
Value of variable is set Array is Empty34
Value of variable is set Array is Empty35
Value of variable is set Array is Empty3____337
Value of variable is set Array is Empty3______328
Value of variable is set Array is Empty29
Value of variable is set Array is Empty2____331
Value of variable is set Array is Empty32
Value of variable is set Array is Empty33
Value of variable is set Array is Empty34
Value of variable is set Array is Empty35
Value of variable is set Array is Empty3____348
Value of variable is set Array is Empty3______328
Value of variable is set Array is Empty29
Value of variable is set Array is Empty5____331
Value of variable is set Array is Empty32____333
Value of variable is set Array is Empty34
Value of variable is set Array is Empty35
Value of variable is set Array is Empty3____339
Value of variable is set Array is Empty3______328
Value of variable is set Array is Empty29
$age = 0; // Evaluates as true because $age is set if [isset[$age]] { echo '$age is set even though it is empty'; }00
Value of variable is set Array is Empty31
Value of variable is set Array is Empty32____333
Value of variable is set Array is Empty34
Value of variable is set Array is Empty35
Value of variable is set Array is Empty3____330
Value of variable is set Array is Empty3______328
Value of variable is set Array is Empty29
$age = 0; // Evaluates as true because $age is set if [isset[$age]] { echo '$age is set even though it is empty'; }03______331
Value of variable is set Array is Empty32
Value of variable is set Array is Empty33
Value of variable is set Array is Empty34
Value of variable is set Array is Empty35
Value of variable is set Array is Empty3____381
Value of variable is set Array is Empty3______328
Value of variable is set Array is Empty29
$age = 0; // Evaluates as true because $age is set if [isset[$age]] { echo '$age is set even though it is empty'; }06
Value of variable is set Array is Empty31
Value of variable is set Array is Empty32
Value of variable is set Array is Empty33
Value of variable is set Array is Empty34
Value of variable is set Array is Empty35
Value of variable is set Array is Empty3____302
Value of variable is set Array is Empty3______328
Value of variable is set Array is Empty29
Value of variable is set Array is Empty21
Value of variable is set Array is Empty31
Value of variable is set Array is Empty32____333
Value of variable is set Array is Empty34
Value of variable is set Array is Empty35
Value of variable is set Array is Empty3____313
Value of variable is set Array is Empty3______328
Value of variable is set Array is Empty29
Value of variable is set Array is Empty17
Value of variable is set Array is Empty31
Value of variable is set Array is Empty32
Value of variable is set Array is Empty33
Value of variable is set Array is Empty34
Value of variable is set Array is Empty35
Value of variable is set Array is Empty23
Đầu ra
$age is set even though it is empty9
hàm isset[]. Hàm isset[] là một hàm có sẵn trong PHP được sử dụng để xác định xem biến có được khai báo hay không và giá trị của nó không bằng NULL