Hướng dẫn how do you check php object is empty or not? - Làm thế nào để bạn kiểm tra đối tượng php trống hay không?

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 ¶

Denobocation-bozic et yahoo.com

$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à trống hay null PHP?

hàm trống () trong PHP? Hàm isset () là một hàm sẵn có trong PHP, kiểm tra xem một biến được đặt và không phải là null. Hàm này cũng kiểm tra xem một biến được khai báo, mảng hoặc khóa mảng có giá trị null, nếu có, isset () trả về false, nó trả về đúng trong tất cả các trường hợp có thể khác.The isset() function is an inbuilt function in PHP which checks whether a variable is set and is not NULL. This function also checks if a declared variable, array or array key has null value, if it does, isset() returns false, it returns true in all other possible cases.

Những gì được coi là trống trong PHP?

Một biến được coi là trống nếu nó không tồn tại hoặc nếu giá trị của nó bằng sai.trống () không tạo ra cảnh báo nếu biến không tồn tại.if it does not exist or if its value equals false . empty() does not generate a warning if the variable does not exist.

Làm thế nào để kiểm tra nếu mảng là php trống?

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

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

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.