Được đặt so với null php?

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 Empty
0 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 Empty
1

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 Empty
2

 

Value of variable is set
Array is Empty
3____34

Value of variable is set
Array is Empty
3____36

Value of variable is set
Array is Empty
3
Value of variable is set
Array is Empty
8
Value of variable is set
Array is Empty
0

Value of variable is set
Array is Empty
3______32
Value of variable is set
Array is Empty
3

Value of variable is set
Array is Empty
3
Value of variable is set
Array is Empty
5
Value of variable is set
Array is Empty
6
Value of variable is set
Array is Empty
7
Value of variable is set
Array is Empty
8

________ 33 ________ 100 ________ 101

________ 33 ________ 103 ________ 104

Value of variable is set
Array is Empty
3____106
Value of variable is set
Array is Empty
6
$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 Empty
3____321
Value of variable is set
Array is Empty
6____323
Value of variable is set
Array is Empty
8

 

Value of variable is set
Array is Empty
3____326

____33______328____329

Value of variable is set
Array is Empty
8____331
Value of variable is set
Array is Empty
32____333
Value of variable is set
Array is Empty
34
Value of variable is set
Array is Empty
35

 

Value of variable is set
Array is Empty
3____337

Value of variable is set
Array is Empty
3______328
Value of variable is set
Array is Empty
29
Value of variable is set
Array is Empty
2____331
Value of variable is set
Array is Empty
32
Value of variable is set
Array is Empty
33
Value of variable is set
Array is Empty
34
Value of variable is set
Array is Empty
35

 

Value of variable is set
Array is Empty
3____348

Value of variable is set
Array is Empty
3______328
Value of variable is set
Array is Empty
29
Value of variable is set
Array is Empty
5____331
Value of variable is set
Array is Empty
32____333
Value of variable is set
Array is Empty
34
Value of variable is set
Array is Empty
35

 

Value of variable is set
Array is Empty
3____339

Value of variable is set
Array is Empty
3______328
Value of variable is set
Array is Empty
29
$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 Empty
31
Value of variable is set
Array is Empty
32____333
Value of variable is set
Array is Empty
34
Value of variable is set
Array is Empty
35

 

Value of variable is set
Array is Empty
3____330

Value of variable is set
Array is Empty
3______328
Value of variable is set
Array is Empty
29
$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 Empty
32
Value of variable is set
Array is Empty
33
Value of variable is set
Array is Empty
34
Value of variable is set
Array is Empty
35

 

Value of variable is set
Array is Empty
3____381

Value of variable is set
Array is Empty
3______328
Value of variable is set
Array is Empty
29
$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 Empty
31
Value of variable is set
Array is Empty
32
Value of variable is set
Array is Empty
33
Value of variable is set
Array is Empty
34
Value of variable is set
Array is Empty
35

 

Value of variable is set
Array is Empty
3____302

Value of variable is set
Array is Empty
3______328
Value of variable is set
Array is Empty
29
Value of variable is set
Array is Empty
21
Value of variable is set
Array is Empty
31
Value of variable is set
Array is Empty
32____333
Value of variable is set
Array is Empty
34
Value of variable is set
Array is Empty
35

 

Value of variable is set
Array is Empty
3____313

Value of variable is set
Array is Empty
3______328
Value of variable is set
Array is Empty
29
Value of variable is set
Array is Empty
17
Value of variable is set
Array is Empty
31
Value of variable is set
Array is Empty
32
Value of variable is set
Array is Empty
33
Value of variable is set
Array is Empty
34
Value of variable is set
Array is Empty
35

 

Value of variable is set
Array is Empty
23

Đầu ra

$age is set even though it is empty
9

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

Được đặt so với null?

is_null[] đối lập với isset[] , ngoại trừ một điểm khác biệt là isset[] có thể được áp dụng cho các biến không xác định, nhưng is_null[] chỉ áp dụng cho các biến đã khai báo.

Được đặt và không phải là null PHP?

Hàm isset[] là một hàm có sẵn 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 đặt so với trống?

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

PHP có được đặt null không?

null là giá trị duy nhất có thể có của loại null . Một biến được coi là null nếu. nó đã được gán hằng số null. nó chưa được đặt thành bất kỳ giá trị nào.

Chủ Đề