Php kiểm tra đối tượng stdClass trống

stdClass là lớp trống trong PHP được sử dụng để chuyển các loại khác thành đối tượng. Nó tương tự như đối tượng Java hoặc Python. stdClass không phải là lớp cơ sở của các đối tượng. Nếu một đối tượng được chuyển đổi thành đối tượng, nó không bị sửa đổi. Tuy nhiên, nếu kiểu đối tượng được chuyển đổi/ép kiểu thì một thể hiện của stdClass được tạo, nếu nó không phải là NULL. Nếu nó là NULL, phiên bản mới sẽ trống

công dụng

  • stdClass truy cập trực tiếp các thành viên bằng cách gọi họ
  • Nó rất hữu ích trong đối tượng động
  • Nó được sử dụng để thiết lập các thuộc tính động, v.v.

chương trình 1. Sử dụng mảng để lưu trữ dữ liệu




stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
9

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
0

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
1

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
2
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
3____84
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
0

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
1
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
2
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
3
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
4
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
5

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
1
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
7
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
3
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
9
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
5

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
1
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
22
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
3____124
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
5

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
1
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
27
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
3____129

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
00

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
01

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
02

________ 203 ________ 82 ________ 200

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
06

đầu ra.

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
6

chương trình 2. Sử dụng stdClass thay vì mảng để lưu trữ chi tiết nhân viên [thuộc tính động]




stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
9

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
0

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
09

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
90
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
3______792
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
93

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
90
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
95
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
4
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
97

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
90
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
99
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
9
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
97

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
90
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
03
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
24
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
97

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
90
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
07
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
08
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
97

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
0

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
11

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
03
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
90
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
00

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
06

đầu ra.

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]

Ghi chú. Có thể truyền kiểu của mảng thành đối tượng và đối tượng thành mảng

chương trình 3. Chuyển đổi mảng thành đối tượng




stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
9

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
01

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
18

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
2
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
3____84
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
0

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
1
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
2
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
3
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
4
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
5

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
1
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
7
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
3
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
9
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
5

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
1
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
22
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
3____124
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
5

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
1
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
27
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
3____129

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
00

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
01

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
44

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
45
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
46
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
2
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
97

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
0

________ 203 ________ 845 ________ 200

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
06

đầu ra.

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
2

chương trình 4. Chuyển đổi thuộc tính đối tượng thành mảng




stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
9

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
0

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
09

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
90
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
3______792
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
93

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
90
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
95
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
4
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
97

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
90
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
99
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
9
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
97

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
90
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
03
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
24
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
97

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
90
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
07
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
08
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
97

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
01

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
28

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
29

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
30
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
31
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
4
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
33
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
90
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
97

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
01

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
37

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
03
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
30
stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
00

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
06

đầu ra.

stdClass Object
[
    [name] => John Doe
    [position] => Software Engineer
    [address] => 53, nth street, city
    [status] => Best
]
0

PHP là ngôn ngữ kịch bản phía máy chủ được thiết kế dành riêng cho phát triển web. Bạn có thể học PHP từ đầu bằng cách làm theo Hướng dẫn PHP và Ví dụ về PHP này

Làm cách nào để kiểm tra xem một đối tượng stdClass có trống trong PHP không?

Kiểm tra xem có phải đếm[ [array]$yourObject] ] == 0 .

Làm cách nào để kiểm tra xem đối tượng có trống trong PHP không?

Hàm PHP empty[] . Hàm này trả về false nếu biến tồn tại và không rỗng, ngược lại trả về true. Các giá trị sau ước tính trống. 0.

Làm cách nào để kiểm tra xem đối tượng JSON có trống trong PHP không?

$configuration = json_decode[shop[]->setting->whatsapp_configuration, true]->send_message_via; Bây giờ, nếu nó trống như thế này [] , thì tôi nhận được . Nếu không thì hoạt động tốt.

stdClass có phải là một đối tượng không?

StdClass là lớp trống trong PHP được sử dụng để truyền các loại khác thành đối tượng . Nó tương tự như đối tượng Java hoặc Python. stdClass không phải là lớp cơ sở của các đối tượng. Nếu một đối tượng được chuyển đổi thành đối tượng, nó không bị sửa đổi.

Chủ Đề