开发者

Get count of inner objects

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜