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++;
}
}
精彩评论