Hướng dẫn is empty array true in php? - mảng trống có đúng trong php không?

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

/**
* @author :  Nanhe Kumar <>
* List of all empty values
**/
$testCase = array(
   
1 => '',
   
2 => "",
   
3 => null,
   
4 => array(),
   
5 => FALSE,
   
6 => NULL,
   
7=>'0',
   
8=>0,

    );

$var0

$var1

Janci ¶

13 năm trước

$var2

$var3

$var4

$var5

Steven tại Nevvix Dot Com ¶

11 năm trước

$var6

$var7

$var5

Thông tin tại Ensostudio Dot Ru ¶

1 năm trước

$var9

Markmanning tại Gmail Dot Com ¶

3 năm trước

var0

var1

var2

var3

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

7 năm trước

var4

var5

var6

Martin Dot Aarhof tại Gmail Dot Com ¶

10 năm trước

var7

var8

$var5

Ẩn danh ¶

14 năm trước

true0

true1

true2

true3

$var5

Chrisdmiddleton tại Gmail Dot Com ¶

8 năm trước

true5

true6

true7

Janci ¶

13 năm trước

true8

Steven tại Nevvix Dot Com ¶

13 năm trước

true9

Steven tại Nevvix Dot Com ¶

11 năm trước

var0

Thông tin tại Ensostudio Dot Ru ¶

13 năm trước

var1

var2

var3

var4

Steven tại Nevvix Dot Com ¶

14 năm trước

var5

var6

$var5

Chrisdmiddleton tại Gmail Dot Com ¶

wranvaud tại gmail dot com ¶

var8

5 năm trước

11 năm trước

var9

false0

false1

false2

$var5

Thông tin tại Ensostudio Dot Ru ¶

wranvaud tại gmail dot com ¶

false4

false5

false6

$var5

5 năm trước

13 năm trước

false8

false9

$var5

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

$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';
}
?>
3

$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

$var5

5 năm trước

Claudio Galdiolo ¶

$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

$var5

phpsort ¶

Denobocation-bozic et yahoo.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

$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

$var5

Tom tại Tomwardrop Dot Com ¶

13 năm trước

$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']));
?>
6

$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

$var5

Steven tại Nevvix Dot Com ¶

11 năm trước

$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']));
?>
9

/**
* @author :  Nanhe Kumar <>
* List of all empty values
**/
$testCase = array(
   
1 => '',
   
2 => "",
   
3 => null,
   
4 => array(),
   
5 => FALSE,
   
6 => NULL,
   
7=>'0',
   
8=>0,
0

$var5

Thông tin tại Ensostudio Dot Ru ¶

3 năm trước

/**
* @author :  Nanhe Kumar <>
* List of all empty values
**/
$testCase = array(
   
1 => '',
   
2 => "",
   
3 => null,
   
4 => array(),
   
5 => FALSE,
   
6 => NULL,
   
7=>'0',
   
8=>0,
2

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

14 năm trước

/**
* @author :  Nanhe Kumar <>
* List of all empty values
**/
$testCase = array(
   
1 => '',
   
2 => "",
   
3 => null,
   
4 => array(),
   
5 => FALSE,
   
6 => NULL,
   
7=>'0',
   
8=>0,
3

/**
* @author :  Nanhe Kumar <>
* List of all empty values
**/
$testCase = array(
   
1 => '',
   
2 => "",
   
3 => null,
   
4 => array(),
   
5 => FALSE,
   
6 => NULL,
   
7=>'0',
   
8=>0,
4

/**
* @author :  Nanhe Kumar <>
* List of all empty values
**/
$testCase = array(
   
1 => '',
   
2 => "",
   
3 => null,
   
4 => array(),
   
5 => FALSE,
   
6 => NULL,
   
7=>'0',
   
8=>0,
5

/**
* @author :  Nanhe Kumar <>
* List of all empty values
**/
$testCase = array(
   
1 => '',
   
2 => "",
   
3 => null,
   
4 => array(),
   
5 => FALSE,
   
6 => NULL,
   
7=>'0',
   
8=>0,
6

$var5

Chrisdmiddleton tại Gmail Dot Com ¶

wranvaud tại gmail dot com ¶

/**
* @author :  Nanhe Kumar <>
* List of all empty values
**/
$testCase = array(
   
1 => '',
   
2 => "",
   
3 => null,
   
4 => array(),
   
5 => FALSE,
   
6 => NULL,
   
7=>'0',
   
8=>0,
8

5 năm trước

Claudio Galdiolo ¶

/**
* @author :  Nanhe Kumar <>
* List of all empty values
**/
$testCase = array(
   
1 => '',
   
2 => "",
   
3 => null,
   
4 => array(),
   
5 => FALSE,
   
6 => NULL,
   
7=>'0',
   
8=>0,
9

    );0

    );1

    );2

    );3

$var5

phpsort ¶

11 năm trước

    );5

    );6

$var5

Thông tin tại Ensostudio Dot Ru ¶

10 năm trước

    );8

    );9

$var5

Ẩn danh ¶

wranvaud tại gmail dot com ¶

$var01

$var02

$var03

$var04

$var05

$var06

$var5

5 năm trước

Claudio Galdiolo ¶

$var08

$var0

$var10

phpsort ¶

Denobocation-bozic et yahoo.com

$var11

$var12

$var13

$var5

Tom tại Tomwardrop Dot Com ¶

Denobocation-bozic et yahoo.com

$var15

$var16

$var17

$var18

$var19

Tom tại Tomwardrop Dot Com ¶

13 năm trước

$var20

$var21

$var5

Steven tại Nevvix Dot Com ¶

Denobocation-bozic et yahoo.com

$var23

$var24

$var25

Mảng trống có đúng không?

Các giá trị không nằm trong danh sách các giá trị giả trong JavaScript được gọi là các giá trị sự thật và bao gồm mảng trống [] hoặc đối tượng trống {}.Điều này có nghĩa là hầu hết mọi thứ đều đánh giá đúng trong JavaScript - bất kỳ đối tượng nào và hầu hết tất cả các giá trị nguyên thủy, mọi thứ trừ các giá trị giả.almost everything evaluates to true in JavaScript — any object and almost all primitive values, everything but the falsy values.

Là một mảng trống php trống?

Một mảng trống là giả trong PHP, vì vậy bạn thậm chí không cần phải sử dụng trống () như những người khác đã đề xuất.PHP trống () của PHP xác định xem một biến không tồn tại hay có giá trị giả (như mảng (), 0, null, false, v.v.)., so you don't even need to use empty() as others have suggested. PHP's empty() determines if a variable doesn't exist or has a falsey value (like array() , 0 , null , false , etc).

Trống có sai trong PHP không?

Hàm php trố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.This function returns false if the variable exists and is not empty, otherwise it returns true. The following values evaluates to empty: 0.

Mảng trống có được coi là sai không?

Kết luận.Bởi vì mảng là loại đối tượng, thực tế là một mảng trống được trò chuyện đúng là chính xác.an empty Array is conversed to true is correct.