Hướng dẫn php check empty but not zero - kiểm tra php trống nhưng không phải số không

Điều này sẽ làm những gì bạn muốn:

function notempty($var) {
    return ($var==="0"||$var);
}

Chỉnh sửa: Tôi đoán các bảng chỉ hoạt động trong bản xem trước, không phải trong các bài nộp trả lời thực tế. Vì vậy, vui lòng tham khảo các bảng so sánh loại PHP để biết thêm thông tin.

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true

Về cơ bản, notempty () giống như! Clan () cho tất cả các giá trị ngoại trừ "0", mà nó trả về true.true.


Chỉnh sửa: Nếu bạn đang sử dụng Error_Reporting (e_all), bạn sẽ không thể chuyển một biến không xác định cho các hàm tùy chỉnh theo giá trị. Và như Mercator chỉ ra, bạn nên luôn luôn sử dụng e_all để phù hợp với các thực tiễn tốt nhất. Liên kết này (nhận xét số 11), anh ấy cung cấp thảo luận về lý do tại sao bạn không nên sử dụng bất kỳ hình thức giảm lỗi nào cho hiệu suất và khả năng bảo trì/gỡ lỗi.error_reporting(E_ALL), you will not be able to pass an undefined variable to custom functions by value. And as mercator points out, you should always use E_ALL to conform to best practices. This link (comment #11) he provides discusses why you shouldn't use any form of error suppression for performance and maintainability/debugging reasons.

Xem câu trả lời của Orlandu63 về cách sử dụng các đối số được chuyển đến một hàm tùy chỉnh bằng cách tham khảo.

(Php 4, Php 5, Php 7, Php 8)

trống - xác định xem một biến có trống khôngDetermine whether a variable is empty

Sự mô tả

trống rỗng (hỗn hợp $var): bool(mixed $var): bool

Thông số

var

Biến cần được kiểm tra

Không có cảnh báo nào được tạo ra nếu biến không tồn tại. Điều đó có nghĩa là trống () về cơ bản là tương đương ngắn gọn với! ISSET ($ var) || $ var == Sai.empty() is essentially the concise equivalent to !isset($var) || $var == false.

Trả về giá trị

Trả về true Nếu var không tồn tại hoặc có giá trị trống hoặc bằng 0, hay còn gọi là Fisey, xem chuyển đổi sang Boolean. Nếu không thì trả về false.true if var does not exist or has a value that is empty or equal to zero, aka falsey, see conversion to boolean. Otherwise returns false.

Ví dụ

Ví dụ #1 Một so sánh đơn giản trống () / isset ().empty() / isset() comparison.

$var 0;// Evaluates to true because $var is empty
if (empty($var)) {
    echo 
'$var is either 0, empty, or not set at all';
}
// Evaluates as true because $var is set
if (isset($var)) {
    echo 
'$var is set even though it is empty';
}
?>

Ví dụ #2 trống () trên chuỗi offsetsempty() on String Offsets

$expected_array_got_string 'somestring';
var_dump(empty($expected_array_got_string['some_key']));
var_dump(empty($expected_array_got_string[0]));
var_dump(empty($expected_array_got_string['0']));
var_dump(empty($expected_array_got_string[0.5]));
var_dump(empty($expected_array_got_string['0.5']));
var_dump(empty($expected_array_got_string['0 Mostel']));
?>

Ví dụ trên sẽ xuất ra:

bool(true)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)

Ghi chú

Lưu ý: Bởi vì đây là một cấu trúc ngôn ngữ và không phải là một hàm, nó không thể được gọi là sử dụng các hàm biến hoặc các đối số được đặt tên.: Because this is a language construct and not a function, it cannot be called using variable functions, or named arguments.

Ghi chú::

Khi sử dụng trống () trên các thuộc tính đối tượng không thể truy cập, phương thức quá tải __isset () sẽ được gọi, nếu được khai báo.empty() on inaccessible object properties, the __isset() overloading method will be called, if declared.

Xem thêm

  • ISSET () - Xác định xem một biến được khai báo và khác với NULL
  • __isset()
  • unset () - Und đặt một biến đã cho
  • Array_Key_Exists () - Kiểm tra xem khóa hoặc chỉ mục đã cho có tồn tại trong mảng
  • Count () - Đếm tất cả các phần tử trong một mảng hoặc trong một đối tượng có thể đếm được
  • strlen () - Nhận độ dài chuỗi
  • Các bảng so sánh loại

Nanhe Kumar ¶

8 năm trước

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
0

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
1

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
2

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
3

Janci ¶

13 năm trước

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
4

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
5

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
6

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Steven tại Nevvix Dot Com ¶

11 năm trước

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
8

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
9

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Thông tin tại Ensostudio Dot Ru ¶

1 năm trước

bool(true)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
1

Markmanning tại Gmail Dot Com ¶

3 năm trước

bool(true)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
2

bool(true)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
3

bool(true)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
4

bool(true)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
5

anh em chấm của bạn dot t tại hotmail dot com

7 năm trước

bool(true)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
6

bool(true)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
7

bool(true)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
8

Martin Dot Aarhof tại Gmail Dot Com ¶

10 năm trước

bool(true)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
9

$var0

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Ẩn danh ¶

14 năm trước

$var2

$var3

$var4

$var5

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Chrisdmiddleton tại Gmail Dot Com ¶

8 năm trước

$var7

$var8

$var9

Janci ¶

13 năm trước

var0

Steven tại Nevvix Dot Com ¶

13 năm trước

var1

Steven tại Nevvix Dot Com ¶

11 năm trước

var2

Thông tin tại Ensostudio Dot Ru ¶

13 năm trước

var3

var4

var5

var6

Steven tại Nevvix Dot Com ¶

14 năm trước

var7

var8

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Chrisdmiddleton tại Gmail Dot Com ¶

wranvaud tại gmail dot com ¶

true0

5 năm trước

11 năm trước

true1

true2

true3

true4

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Thông tin tại Ensostudio Dot Ru ¶

wranvaud tại gmail dot com ¶

true6

true7

true8

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

5 năm trước

13 năm trước

var0

var1

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Steven tại Nevvix Dot Com ¶

wranvaud tại gmail dot com ¶

var3

var4

var5

var6

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

5 năm trước

Claudio Galdiolo ¶

var8

var9

false0

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

phpsort ¶

Denobocation-bozic et yahoo.com

false2

false3

false4

false5

false6

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Tom tại Tomwardrop Dot Com ¶

13 năm trước

false8

false9

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Steven tại Nevvix Dot Com ¶

wranvaud tại gmail dot com ¶

$var 0;// Evaluates to true because $var is empty
if (empty($var)) {
    echo 
'$var is either 0, empty, or not set at all';
}
// Evaluates as true because $var is set
if (isset($var)) {
    echo 
'$var is set even though it is empty';
}
?>
1

$var 0;// Evaluates to true because $var is empty
if (empty($var)) {
    echo 
'$var is either 0, empty, or not set at all';
}
// Evaluates as true because $var is set
if (isset($var)) {
    echo 
'$var is set even though it is empty';
}
?>
2

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

5 năm trước

3 năm trước

$var 0;// Evaluates to true because $var is empty
if (empty($var)) {
    echo 
'$var is either 0, empty, or not set at all';
}
// Evaluates as true because $var is set
if (isset($var)) {
    echo 
'$var is set even though it is empty';
}
?>
4

anh em chấm của bạn dot t tại hotmail dot com

14 năm trước

$var 0;// Evaluates to true because $var is empty
if (empty($var)) {
    echo 
'$var is either 0, empty, or not set at all';
}
// Evaluates as true because $var is set
if (isset($var)) {
    echo 
'$var is set even though it is empty';
}
?>
5

$var 0;// Evaluates to true because $var is empty
if (empty($var)) {
    echo 
'$var is either 0, empty, or not set at all';
}
// Evaluates as true because $var is set
if (isset($var)) {
    echo 
'$var is set even though it is empty';
}
?>
6

$var 0;// Evaluates to true because $var is empty
if (empty($var)) {
    echo 
'$var is either 0, empty, or not set at all';
}
// Evaluates as true because $var is set
if (isset($var)) {
    echo 
'$var is set even though it is empty';
}
?>
7

$var 0;// Evaluates to true because $var is empty
if (empty($var)) {
    echo 
'$var is either 0, empty, or not set at all';
}
// Evaluates as true because $var is set
if (isset($var)) {
    echo 
'$var is set even though it is empty';
}
?>
8

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Chrisdmiddleton tại Gmail Dot Com ¶

wranvaud tại gmail dot com ¶

$expected_array_got_string 'somestring';
var_dump(empty($expected_array_got_string['some_key']));
var_dump(empty($expected_array_got_string[0]));
var_dump(empty($expected_array_got_string['0']));
var_dump(empty($expected_array_got_string[0.5]));
var_dump(empty($expected_array_got_string['0.5']));
var_dump(empty($expected_array_got_string['0 Mostel']));
?>
0

5 năm trước

Claudio Galdiolo ¶

$expected_array_got_string 'somestring';
var_dump(empty($expected_array_got_string['some_key']));
var_dump(empty($expected_array_got_string[0]));
var_dump(empty($expected_array_got_string['0']));
var_dump(empty($expected_array_got_string[0.5]));
var_dump(empty($expected_array_got_string['0.5']));
var_dump(empty($expected_array_got_string['0 Mostel']));
?>
1

$expected_array_got_string 'somestring';
var_dump(empty($expected_array_got_string['some_key']));
var_dump(empty($expected_array_got_string[0]));
var_dump(empty($expected_array_got_string['0']));
var_dump(empty($expected_array_got_string[0.5]));
var_dump(empty($expected_array_got_string['0.5']));
var_dump(empty($expected_array_got_string['0 Mostel']));
?>
2

$expected_array_got_string 'somestring';
var_dump(empty($expected_array_got_string['some_key']));
var_dump(empty($expected_array_got_string[0]));
var_dump(empty($expected_array_got_string['0']));
var_dump(empty($expected_array_got_string[0.5]));
var_dump(empty($expected_array_got_string['0.5']));
var_dump(empty($expected_array_got_string['0 Mostel']));
?>
3

$expected_array_got_string 'somestring';
var_dump(empty($expected_array_got_string['some_key']));
var_dump(empty($expected_array_got_string[0]));
var_dump(empty($expected_array_got_string['0']));
var_dump(empty($expected_array_got_string[0.5]));
var_dump(empty($expected_array_got_string['0.5']));
var_dump(empty($expected_array_got_string['0 Mostel']));
?>
4

$expected_array_got_string 'somestring';
var_dump(empty($expected_array_got_string['some_key']));
var_dump(empty($expected_array_got_string[0]));
var_dump(empty($expected_array_got_string['0']));
var_dump(empty($expected_array_got_string[0.5]));
var_dump(empty($expected_array_got_string['0.5']));
var_dump(empty($expected_array_got_string['0 Mostel']));
?>
5

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

phpsort ¶

wranvaud tại gmail dot com ¶

$expected_array_got_string 'somestring';
var_dump(empty($expected_array_got_string['some_key']));
var_dump(empty($expected_array_got_string[0]));
var_dump(empty($expected_array_got_string['0']));
var_dump(empty($expected_array_got_string[0.5]));
var_dump(empty($expected_array_got_string['0.5']));
var_dump(empty($expected_array_got_string['0 Mostel']));
?>
7

$expected_array_got_string 'somestring';
var_dump(empty($expected_array_got_string['some_key']));
var_dump(empty($expected_array_got_string[0]));
var_dump(empty($expected_array_got_string['0']));
var_dump(empty($expected_array_got_string[0.5]));
var_dump(empty($expected_array_got_string['0.5']));
var_dump(empty($expected_array_got_string['0 Mostel']));
?>
8

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

5 năm trước

10 năm trước

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
00

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
01

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Ẩn danh ¶

wranvaud tại gmail dot com ¶

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
03

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
04

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
05

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
06

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
07

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
08

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

5 năm trước

Claudio Galdiolo ¶

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
10

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
2

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
12

phpsort ¶

Denobocation-bozic et yahoo.com

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
13

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
14

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
15

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Tom tại Tomwardrop Dot Com ¶

Denobocation-bozic et yahoo.com

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
17

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
18

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
19

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
20

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
21

Tom tại Tomwardrop Dot Com ¶

13 năm trước

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
22

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
23

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
7

Steven tại Nevvix Dot Com ¶

Denobocation-bozic et yahoo.com

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
25

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
26

notempty("")       : false
notempty(null)     : false
notempty(undefined): false
notempty(array())  : false
notempty(false)    : false
notempty(true)     : true
notempty(1)        : true
notempty(0)        : false
notempty(-1)       : true
notempty("1")      : true
notempty("0")      : true
notempty("php")    : true
27

Php có kiểm tra trống cho 0 không?

Hàm trống () kiểm tra xem một biến có trống hay không.Hàm này trả về sai nếu biến tồn tại và không trống, nếu không nó sẽ trả về đúng.Các giá trị sau đánh giá là trống: 0.The following values evaluates to empty: 0.

0 được coi là trống?

"0" được coi là không có giá trị hoặc giá trị trống..

Làm thế nào để bạn kiểm tra xem một chuỗi có trống trong PHP không?

Chúng ta có thể sử dụng hàm trống () để kiểm tra xem chuỗi có trống hay không.Hàm được sử dụng để kiểm tra xem chuỗi có trống hay không.Nó sẽ trả về true nếu chuỗi trống.use empty() function to check whether a string is empty or not. The function is used to check whether the string is empty or not. It will return true if the string is empty.

Làm thế nào kiểm tra mảng trống hoặc không trong PHP?

Sử dụng chức năng đếm: Hàm này đếm tất cả các phần tử trong một mảng.Nếu số lượng phần tử trong mảng bằng 0, thì nó sẽ hiển thị mảng trống.....
Sử dụng hàm sizeof (): Phương pháp này kiểm tra kích thước của mảng.Nếu kích thước của mảng bằng 0 thì mảng trống nếu không thì mảng không trống ..