How to check that an object is empty in PHP?

前端 未结 11 2051
不思量自难忘°
不思量自难忘° 2020-11-29 03:31

How to find if an object is empty or not in PHP.

Following is the code in which $obj is holding XML data. How can I check if it\'s empty or not?

11条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 04:12

    You can cast your object into an array, and test its count like so:

    if(count((array)$obj)) {
       // doStuff
    }
    

提交回复
热议问题