Bài viết trước đã giải thích cách sử dụng cấu trúc ngôn ngữ isset[] để kiểm tra xem một biến đã được xác định và có giá trị chưa trước khi sử dụng nó. Cấu trúc ngôn ngữ trống [] được sử dụng để xác định xem một biến có được khai báo hay không và giá trị của biến có bằng false không. Điều quan trọng là phải kiểm tra xem một biến có được đặt hay không khi dữ liệu đến từ các nguồn bên ngoài, chẳng hạn như API, dữ liệu được đăng từ một biểu mẫu hoặc tham số truy vấn từ một URL. Các ví dụ trên cho thấy kết quả của việc sử dụng empty[] để xác định xem các biến có được coi là rỗng bởi PHP hay không
Hàm isset[] là một hàm sẵn có trong PHP để kiểm tra xem một biến có được đặt và không phải là NULL hay không. Hàm này cũng kiểm tra xem một biến, mảng hoặc khóa mảng đã khai báo có giá trị null hay không, nếu có, isset[] trả về false, nó trả về true trong tất cả các trường hợp có thể khác
cú pháp.
bool isset[ $var, mixed ]
Thông số. Chức năng này chấp nhận nhiều hơn một tham số. Tham số đầu tiên của hàm này là $var. Tham số này dùng để lưu trữ giá trị của biến
Thí dụ.
PHP
0 is set with isset function array is not set.2
0 is set with isset function array is not set.3
0 is set with isset function array is not set.4
0 is set with isset function array is not set.5
0 is set with isset function array is not set.6
0 is set with isset function array is not set.7
0 is set with isset function array is not set.0
0 is set with isset function array is not set.1
0 is set with isset function array is not set.2
0 is set with isset function array is not set.5
0 is set with isset function array is not set.4
0 is set with isset function array is not set.5
0 is set with isset function array is not set.6
0 is set with isset function array is not set.7
0 is set with isset function array is not set.8
0 is set with isset function array is not set.9
0 is set with isset function array is not set.00
________ 101 ________ 66 ________ 103 ________ 104
0 is set with isset function array is not set.05
0 is set with isset function array is not set.06
0 is set with isset function array is not set.07
0 is set with isset function array is not set.08_______101
0 is set with isset function array is not set.90
0 is set with isset function array is not set.91
0 is set with isset function array is not set.92
________ 193 ________ 194 ________ 195 ________ 10
0 is set with isset function array is not set.97
đầu ra.
0 is set with isset function array is not set.
chức năng rỗng []
Hàm empty[] là một cấu trúc ngôn ngữ để xác định xem biến đã cho là rỗng hay NULL. Các. Hàm trống [] là phủ định hoặc bổ sung của hàm trống []. Hàm trống [] đáng kể bằng. hàm isset[] và. Hàm empty[] bằng với hàm isset[]
Thí dụ.
PHP
0 is set with isset function array is not set.2
0 is set with isset function array is not set.3
0 is set with isset function array is not set.20
________ 621 ________ 622
0 is set with isset function array is not set.23
0 is set with isset function array is not set.24
0 is set with isset function array is not set.1
0 is set with isset function array is not set.26______627
0 is set with isset function array is not set.26
0 is set with isset function array is not set.21
0 is set with isset function array is not set.30
0 is set with isset function array is not set.5
0 is set with isset function array is not set.07
0 is set with isset function array is not set.21
0 is set with isset function array is not set.34
0 is set with isset function array is not set.35
0 is set with isset function array is not set.0
0 is set with isset function array is not set.9
________ 107 ________ 639 ________ 10
0 is set with isset function array is not set.41
0 is set with isset function array is not set.42
0 is set with isset function array is not set.43
0 is set with isset function array is not set.1
0 is set with isset function array is not set.45____627
0 is set with isset function array is not set.26
0 is set with isset function array is not set.42
0 is set with isset function array is not set.30
0 is set with isset function array is not set.5
0 is set with isset function array is not set.07
0 is set with isset function array is not set.42
0 is set with isset function array is not set.34
0 is set with isset function array is not set.54
0 is set with isset function array is not set.0
0 is set with isset function array is not set.9
0 is set with isset function array is not set.97
đầu ra.
0 is set with isset function array is not set.0
Lý do để kiểm tra cả hai chức năng.
Tập hợp [] và. Các hàm trống [] tương tự nhau và cả hai sẽ trả về cùng một kết quả. Nhưng sự khác biệt duy nhất là. Hàm empty[] sẽ không tạo bất kỳ cảnh báo hoặc thông báo điện tử nào khi biến không tồn tại. Nó là đủ để sử dụng một trong hai chức năng. Bằng cách kết hợp cả hai chức năng trong một chương trình gây ra thời gian trôi đi và sử dụng bộ nhớ không cần thiết.
Thí dụ.
PHP
0 is set with isset function array is not set.2
0 is set with isset function array is not set.59
0 is set with isset function array is not set.60
0 is set with isset function array is not set.61
0 is set with isset function array is not set.5
0 is set with isset function array is not set.6
0 is set with isset function array is not set.7
0 is set with isset function array is not set.0
0 is set with isset function array is not set.66
0 is set with isset function array is not set.1
0 is set with isset function array is not set.68
0 is set with isset function array is not set.5
0 is set with isset function array is not set.4
0 is set with isset function array is not set.5
0 is set with isset function array is not set.6
0 is set with isset function array is not set.5
0 is set with isset function array is not set.34
0 is set with isset function array is not set.75
0 is set with isset function array is not set.8
0 is set with isset function array is not set.9
0 is set with isset function array is not set.78
________ 107 ________ 639 ________ 10
0 is set with isset function array is not set.02
0 is set with isset function array is not set.5
0 is set with isset function array is not set.43
0 is set with isset function array is not set.05
0 is set with isset function array is not set.1
0 is set with isset function array is not set.07
0 is set with isset function array is not set.27
0 is set with isset function array is not set.26
0 is set with isset function array is not set.5
0 is set with isset function array is not set.4
0 is set with isset function array is not set.5
0 is set with isset function array is not set.6
0 is set with isset function array is not set.5
0 is set with isset function array is not set.34
0 is set with isset function array is not set.16
0 is set with isset function array is not set.8
0 is set with isset function array is not set.9
đầu ra.
0 is set with isset function array is not set.9
PHP là ngôn ngữ kịch bản phía máy chủ được thiết kế dành riêng cho phát triển web. Bạn có thể học PHP từ đầu bằng cách làm theo Hướng dẫn PHP và Ví dụ về PHP này