开发者

Get count of inner objects

开发者 https://www.devze.com 2023-01-14 11:07 出处:网络
How would you get the count of the objects inside o开发者_开发百科f this object. We only want to count the two inner objects Count This And This. So our answer will be two.

How would you get the count of the objects inside o开发者_开发百科f this object. We only want to count the two inner objects Count This And This. So our answer will be two.

Here is the object

stdClass Object (

[Count This] => stdClass Object
    (
        [arr] => Array
            (
                [0] => data
                [1] => some data
            )
    )

[And This] => stdClass Object
    (
        [anotherArr] => Array
            (
                [0] => more data
            )
    ) 

)


This is exact answer $total = count((array)$obj);


$count = 0;
foreach($theobject as $var)
{
  if(gettype($var) == 'object')
  {
     $count++;
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消