开发者

php access object within object

开发者 https://www.devze.com 2023-03-30 01:27 出处:网络
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 variab

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.

0

精彩评论

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