Hướng dẫn how to check if object is empty php? - cách kiểm tra xem đối tượng có trống không php?

Chỉnh sửa: Tôi không nhận ra họ muốn kiểm tra cụ thể liệu một đối tượng SimplexMlelement có trống không. Tôi đã để lại câu trả lời cũ bên dưới: I didn't realize they wanted to specifically check if a SimpleXMLElement object is empty. I left the old answer below

Trả lời cập nhật (SimplexMlelement)::

Đối với SimplexMlelement:

Nếu trống, bạn có nghĩa là không có thuộc tính:

$obj = simplexml_load_file($url);
if ( !$obj->count() )
{
    // no properties
}

HOẶC

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}

Nếu SimplexMlelement là một cấp độ sâu và bằng cách trống, bạn thực sự có nghĩa là nó chỉ có thuộc tính PHP xem xét FALSEY (hoặc không có thuộc tính):

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}

Nếu SimplexMlelement sâu hơn một cấp, bạn có thể bắt đầu bằng cách chuyển đổi nó thành một mảng thuần túy:

$obj = simplexml_load_file($url);
// `json_decode(json_encode($obj), TRUE)` can be slow because
// you're converting to and from a JSON string.
// I don't know another simple way to do a deep conversion from object to array
$array = json_decode(json_encode($obj), TRUE);
if ( !array_filter($array) )
{
    // empty or all properties falsey
}

Câu trả lời cũ (đối tượng đơn giản)::

Nếu bạn muốn kiểm tra xem một đối tượng đơn giản (loại stdClass) hoàn toàn trống (không có khóa/giá trị), bạn có thể làm như sau:

// $obj is type stdClass and we want to check if it's empty
if ( $obj == new stdClass() )
{
    echo "Object is empty"; // JSON: {}
}
else
{
    echo "Object has properties";
}

Nguồn: http://php.net/manual/en/language.oop5.Object-comparison.php

Chỉnh sửa: Đã thêm ví dụ: added example

$one = new stdClass();
$two = (object)array();

var_dump($one == new stdClass()); // TRUE
var_dump($two == new stdClass()); // TRUE
var_dump($one == $two); // TRUE

$two->test = TRUE;
var_dump($two == new stdClass()); // FALSE
var_dump($one == $two); // FALSE

$two->test = FALSE;
var_dump($one == $two); // FALSE

$two->test = NULL;
var_dump($one == $two); // FALSE

$two->test = TRUE;
$one->test = TRUE;
var_dump($one == $two); // TRUE

unset($one->test, $two->test);
var_dump($one == $two); // TRUE

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

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
0 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ề
$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
2.
$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
0
if var does not exist or has a value that is empty or equal to zero, aka falsey, see conversion to boolean. Otherwise returns
$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
2
.

Ví dụ

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

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
3

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

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
4

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

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
5

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
6

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
7

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
8

Janci ¶

13 năm trước

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
9

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
0

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
1

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Steven tại Nevvix Dot Com ¶

11 năm trước

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
3

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
4

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Thông tin tại Ensostudio Dot Ru ¶

1 năm trước

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
6

Markmanning tại Gmail Dot Com ¶

3 năm trước

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
7

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
8

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
9

$obj = simplexml_load_file($url);
// `json_decode(json_encode($obj), TRUE)` can be slow because
// you're converting to and from a JSON string.
// I don't know another simple way to do a deep conversion from object to array
$array = json_decode(json_encode($obj), TRUE);
if ( !array_filter($array) )
{
    // empty or all properties falsey
}
0

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

7 năm trước

$obj = simplexml_load_file($url);
// `json_decode(json_encode($obj), TRUE)` can be slow because
// you're converting to and from a JSON string.
// I don't know another simple way to do a deep conversion from object to array
$array = json_decode(json_encode($obj), TRUE);
if ( !array_filter($array) )
{
    // empty or all properties falsey
}
1

$obj = simplexml_load_file($url);
// `json_decode(json_encode($obj), TRUE)` can be slow because
// you're converting to and from a JSON string.
// I don't know another simple way to do a deep conversion from object to array
$array = json_decode(json_encode($obj), TRUE);
if ( !array_filter($array) )
{
    // empty or all properties falsey
}
2

$obj = simplexml_load_file($url);
// `json_decode(json_encode($obj), TRUE)` can be slow because
// you're converting to and from a JSON string.
// I don't know another simple way to do a deep conversion from object to array
$array = json_decode(json_encode($obj), TRUE);
if ( !array_filter($array) )
{
    // empty or all properties falsey
}
3

Martin Dot Aarhof tại Gmail Dot Com ¶

10 năm trước

$obj = simplexml_load_file($url);
// `json_decode(json_encode($obj), TRUE)` can be slow because
// you're converting to and from a JSON string.
// I don't know another simple way to do a deep conversion from object to array
$array = json_decode(json_encode($obj), TRUE);
if ( !array_filter($array) )
{
    // empty or all properties falsey
}
4

$obj = simplexml_load_file($url);
// `json_decode(json_encode($obj), TRUE)` can be slow because
// you're converting to and from a JSON string.
// I don't know another simple way to do a deep conversion from object to array
$array = json_decode(json_encode($obj), TRUE);
if ( !array_filter($array) )
{
    // empty or all properties falsey
}
5

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Ẩn danh ¶

14 năm trước

$obj = simplexml_load_file($url);
// `json_decode(json_encode($obj), TRUE)` can be slow because
// you're converting to and from a JSON string.
// I don't know another simple way to do a deep conversion from object to array
$array = json_decode(json_encode($obj), TRUE);
if ( !array_filter($array) )
{
    // empty or all properties falsey
}
7

$obj = simplexml_load_file($url);
// `json_decode(json_encode($obj), TRUE)` can be slow because
// you're converting to and from a JSON string.
// I don't know another simple way to do a deep conversion from object to array
$array = json_decode(json_encode($obj), TRUE);
if ( !array_filter($array) )
{
    // empty or all properties falsey
}
8

$obj = simplexml_load_file($url);
// `json_decode(json_encode($obj), TRUE)` can be slow because
// you're converting to and from a JSON string.
// I don't know another simple way to do a deep conversion from object to array
$array = json_decode(json_encode($obj), TRUE);
if ( !array_filter($array) )
{
    // empty or all properties falsey
}
9

// $obj is type stdClass and we want to check if it's empty
if ( $obj == new stdClass() )
{
    echo "Object is empty"; // JSON: {}
}
else
{
    echo "Object has properties";
}
0

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Chrisdmiddleton tại Gmail Dot Com ¶

8 năm trước

// $obj is type stdClass and we want to check if it's empty
if ( $obj == new stdClass() )
{
    echo "Object is empty"; // JSON: {}
}
else
{
    echo "Object has properties";
}
2

// $obj is type stdClass and we want to check if it's empty
if ( $obj == new stdClass() )
{
    echo "Object is empty"; // JSON: {}
}
else
{
    echo "Object has properties";
}
3

// $obj is type stdClass and we want to check if it's empty
if ( $obj == new stdClass() )
{
    echo "Object is empty"; // JSON: {}
}
else
{
    echo "Object has properties";
}
4

Janci ¶

13 năm trước

// $obj is type stdClass and we want to check if it's empty
if ( $obj == new stdClass() )
{
    echo "Object is empty"; // JSON: {}
}
else
{
    echo "Object has properties";
}
5

Steven tại Nevvix Dot Com ¶

13 năm trước

// $obj is type stdClass and we want to check if it's empty
if ( $obj == new stdClass() )
{
    echo "Object is empty"; // JSON: {}
}
else
{
    echo "Object has properties";
}
6

Steven tại Nevvix Dot Com ¶

11 năm trước

// $obj is type stdClass and we want to check if it's empty
if ( $obj == new stdClass() )
{
    echo "Object is empty"; // JSON: {}
}
else
{
    echo "Object has properties";
}
7

Thông tin tại Ensostudio Dot Ru ¶

13 năm trước

// $obj is type stdClass and we want to check if it's empty
if ( $obj == new stdClass() )
{
    echo "Object is empty"; // JSON: {}
}
else
{
    echo "Object has properties";
}
8

// $obj is type stdClass and we want to check if it's empty
if ( $obj == new stdClass() )
{
    echo "Object is empty"; // JSON: {}
}
else
{
    echo "Object has properties";
}
9

$one = new stdClass();
$two = (object)array();

var_dump($one == new stdClass()); // TRUE
var_dump($two == new stdClass()); // TRUE
var_dump($one == $two); // TRUE

$two->test = TRUE;
var_dump($two == new stdClass()); // FALSE
var_dump($one == $two); // FALSE

$two->test = FALSE;
var_dump($one == $two); // FALSE

$two->test = NULL;
var_dump($one == $two); // FALSE

$two->test = TRUE;
$one->test = TRUE;
var_dump($one == $two); // TRUE

unset($one->test, $two->test);
var_dump($one == $two); // TRUE
0

$one = new stdClass();
$two = (object)array();

var_dump($one == new stdClass()); // TRUE
var_dump($two == new stdClass()); // TRUE
var_dump($one == $two); // TRUE

$two->test = TRUE;
var_dump($two == new stdClass()); // FALSE
var_dump($one == $two); // FALSE

$two->test = FALSE;
var_dump($one == $two); // FALSE

$two->test = NULL;
var_dump($one == $two); // FALSE

$two->test = TRUE;
$one->test = TRUE;
var_dump($one == $two); // TRUE

unset($one->test, $two->test);
var_dump($one == $two); // TRUE
1

Steven tại Nevvix Dot Com ¶

14 năm trước

$one = new stdClass();
$two = (object)array();

var_dump($one == new stdClass()); // TRUE
var_dump($two == new stdClass()); // TRUE
var_dump($one == $two); // TRUE

$two->test = TRUE;
var_dump($two == new stdClass()); // FALSE
var_dump($one == $two); // FALSE

$two->test = FALSE;
var_dump($one == $two); // FALSE

$two->test = NULL;
var_dump($one == $two); // FALSE

$two->test = TRUE;
$one->test = TRUE;
var_dump($one == $two); // TRUE

unset($one->test, $two->test);
var_dump($one == $two); // TRUE
2

$one = new stdClass();
$two = (object)array();

var_dump($one == new stdClass()); // TRUE
var_dump($two == new stdClass()); // TRUE
var_dump($one == $two); // TRUE

$two->test = TRUE;
var_dump($two == new stdClass()); // FALSE
var_dump($one == $two); // FALSE

$two->test = FALSE;
var_dump($one == $two); // FALSE

$two->test = NULL;
var_dump($one == $two); // FALSE

$two->test = TRUE;
$one->test = TRUE;
var_dump($one == $two); // TRUE

unset($one->test, $two->test);
var_dump($one == $two); // TRUE
3

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Chrisdmiddleton tại Gmail Dot Com ¶

wranvaud tại gmail dot com ¶

$one = new stdClass();
$two = (object)array();

var_dump($one == new stdClass()); // TRUE
var_dump($two == new stdClass()); // TRUE
var_dump($one == $two); // TRUE

$two->test = TRUE;
var_dump($two == new stdClass()); // FALSE
var_dump($one == $two); // FALSE

$two->test = FALSE;
var_dump($one == $two); // FALSE

$two->test = NULL;
var_dump($one == $two); // FALSE

$two->test = TRUE;
$one->test = TRUE;
var_dump($one == $two); // TRUE

unset($one->test, $two->test);
var_dump($one == $two); // TRUE
5

5 năm trước

11 năm trước

$one = new stdClass();
$two = (object)array();

var_dump($one == new stdClass()); // TRUE
var_dump($two == new stdClass()); // TRUE
var_dump($one == $two); // TRUE

$two->test = TRUE;
var_dump($two == new stdClass()); // FALSE
var_dump($one == $two); // FALSE

$two->test = FALSE;
var_dump($one == $two); // FALSE

$two->test = NULL;
var_dump($one == $two); // FALSE

$two->test = TRUE;
$one->test = TRUE;
var_dump($one == $two); // TRUE

unset($one->test, $two->test);
var_dump($one == $two); // TRUE
6

$one = new stdClass();
$two = (object)array();

var_dump($one == new stdClass()); // TRUE
var_dump($two == new stdClass()); // TRUE
var_dump($one == $two); // TRUE

$two->test = TRUE;
var_dump($two == new stdClass()); // FALSE
var_dump($one == $two); // FALSE

$two->test = FALSE;
var_dump($one == $two); // FALSE

$two->test = NULL;
var_dump($one == $two); // FALSE

$two->test = TRUE;
$one->test = TRUE;
var_dump($one == $two); // TRUE

unset($one->test, $two->test);
var_dump($one == $two); // TRUE
7

$one = new stdClass();
$two = (object)array();

var_dump($one == new stdClass()); // TRUE
var_dump($two == new stdClass()); // TRUE
var_dump($one == $two); // TRUE

$two->test = TRUE;
var_dump($two == new stdClass()); // FALSE
var_dump($one == $two); // FALSE

$two->test = FALSE;
var_dump($one == $two); // FALSE

$two->test = NULL;
var_dump($one == $two); // FALSE

$two->test = TRUE;
$one->test = TRUE;
var_dump($one == $two); // TRUE

unset($one->test, $two->test);
var_dump($one == $two); // TRUE
8

$one = new stdClass();
$two = (object)array();

var_dump($one == new stdClass()); // TRUE
var_dump($two == new stdClass()); // TRUE
var_dump($one == $two); // TRUE

$two->test = TRUE;
var_dump($two == new stdClass()); // FALSE
var_dump($one == $two); // FALSE

$two->test = FALSE;
var_dump($one == $two); // FALSE

$two->test = NULL;
var_dump($one == $two); // FALSE

$two->test = TRUE;
$one->test = TRUE;
var_dump($one == $two); // TRUE

unset($one->test, $two->test);
var_dump($one == $two); // TRUE
9

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Thông tin tại Ensostudio Dot Ru ¶

wranvaud tại gmail dot com ¶

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

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

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

5 năm trước

13 năm trước

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

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

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Steven tại Nevvix Dot Com ¶

wranvaud tại gmail dot com ¶

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

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

stdClass0

stdClass1

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

5 năm trước

Claudio Galdiolo ¶

stdClass3

stdClass4

stdClass5

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

phpsort ¶

Denobocation-bozic et yahoo.com

stdClass7

stdClass8

stdClass9

$var0

$var1

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Tom tại Tomwardrop Dot Com ¶

13 năm trước

$var3

$var4

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Steven tại Nevvix Dot Com ¶

wranvaud tại gmail dot com ¶

$var6

$var7

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

5 năm trước

3 năm trước

$var9

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

14 năm trước

var0

var1

var2

var3

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Chrisdmiddleton tại Gmail Dot Com ¶

wranvaud tại gmail dot com ¶

var5

5 năm trước

Claudio Galdiolo ¶

var6

var7

var8

var9

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
00

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

phpsort ¶

wranvaud tại gmail dot com ¶

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
02

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
03

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

5 năm trước

10 năm trước

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
05

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
06

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Ẩn danh ¶

wranvaud tại gmail dot com ¶

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
08

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
09

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
10

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
11

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
12

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
13

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

5 năm trước

Claudio Galdiolo ¶

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
15

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
7

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
17

phpsort ¶

Denobocation-bozic et yahoo.com

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
18

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
19

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
20

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Tom tại Tomwardrop Dot Com ¶

Denobocation-bozic et yahoo.com

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
22

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
23

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
24

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
25

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
26

Tom tại Tomwardrop Dot Com ¶

13 năm trước

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
27

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
28

$obj = simplexml_load_file($url);
if ( !array_filter((array)$obj) )
{
    // all properties falsey or no properties at all
}
2

Steven tại Nevvix Dot Com ¶

13 năm trước

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
30

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
31

$obj = simplexml_load_file($url);
if ( !(array)$obj )
{
    // empty array
}
32

Là đối tượng trống trong PHP?

Làm thế nào để bạn kiểm tra đối tượng PHP có trống hay 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.The empty() function checks whether a variable is empty or not. This function returns false if the variable exists and is not empty, otherwise it returns true. The following values evaluates to empty: 0.

Làm thế nào phát hiện nếu đối tượng trống?

Sử dụng đối tượng.Sự vật.Các phím sẽ trả về một mảng, chứa tên thuộc tính của đối tượng.Nếu độ dài của mảng là 0, thì chúng ta biết rằng đối tượng trống.If the length of the array is 0 , then we know that the object is empty.

Làm thế nào kiểm tra đối tượng STD trống trong PHP?

Kiểm tra nếu đếm ((mảng) $ yourObject)) == 0. .

Làm thế nào đối tượng kiểm tra là null hay không trong PHP?

Hàm is_null () kiểm tra xem một biến có null hay không.Hàm này trả về true (1) nếu biến là null, nếu không nó sẽ trả về sai/không có gì.is_null() function checks whether a variable is NULL or not. This function returns true (1) if the variable is NULL, otherwise it returns false/nothing.