php access object within object
I have an object in PHP and I'm using a
foreach ($items as $item)
to iterate through the items. However, $item contains another object called $item, 开发者_开发问答which contains the $type variable whose value I need to access. How can I access the value of $type? What I want to do is:
foreach($items as item){
if($item->item->type == 'this'){
//do this
} elseif ($item->item->type == 'that'){
//do that
}
}
But $item->item->type isn't picking up that value. How can I access it and use it for my function?
have you tired:
foreach($items as item){
if($item->type == 'this'){
//do this
} elseif ($item->type == 'that'){
//do that
}
}
or you can debug your code to find out what is going on:
foreach($items as item){
print_r($item);
}
and then you can see what kind of childs this $item has.
精彩评论